views:

15

answers:

1

I know the BindingFlags are used to fetch public and non-public members from a Type.

But is there a way to determine if a MemberInfo instance (or derived like PropertyInfo, MethodInfo) is public or not (after it was returned from one of the methods on Type)?

Thanx, Marc

+2  A: 

Hmm... good question.

PropertyInfo, MethodBase etc each have an Attributes property which has this information - but there's nothing in MemberInfo, because each kind of member has its own kind of attributes enum. Hideous as it is, I think you may need to treat each subclass of MemberInfo separately :( You can probably switch on MemberInfo.MemberType and then cast, which will be slightly nicer than lots of as/test-for-null branches, but it's still not ideal :(

Jon Skeet
Ah, I see. I also see that PropertyInfo does not have PropertyAttribues to indicate its accessability. So I need to get the Accessor methods and go with those. Thanx for your explaination.
obiwanjacobi
@obiwanjacobi: Presumably that's because you can have different accessibility for the get and set.
Jon Skeet