Class Modifiers via Reflection

  • Thread starter Thread starter Kevin Lindsey
  • Start date Start date
K

Kevin Lindsey

Is there a way to determine the access modifiers of a class type in an
assembly via reflection? I see that I can determine if the class is public
or non-public, but I would like to be able to further sub-divide the
non-public modifiers (assembly, family, familyAndAssembly, familyOrAssembly,
private). Is this possible with the .NET 1.1 Reflection API? And just to
clarify, I see I can get this info for nested classes, but I would like it
for non-nested classes too.

Thanks for any suggestions or pointers on this.

Kevin
 
Hi, Kevin

check Type.Attributes property and related TypeAttributes Enumeration -
they should provide you with required information

HTH
Alex
 
Kevin Lindsey said:
Is there a way to determine the access modifiers of a class type in an
assembly via reflection? I see that I can determine if the class is public
or non-public, but I would like to be able to further sub-divide the
non-public modifiers (assembly, family, familyAndAssembly, familyOrAssembly,
private). Is this possible with the .NET 1.1 Reflection API? And just to
clarify, I see I can get this info for nested classes, but I would like it
for non-nested classes too.

Unless the class is nested, it can only be public or internal - it
doesn't make sense for a non-nested type to be protected (family), for
instance.
 
Hi Alex,
check Type.Attributes property and related TypeAttributes Enumeration -
they should provide you with required information

Yeah, that's what I'm using currently, but it does not provide the break
down for non-public classes. Surprisingly to me, it does provide this
information for nested classes, but not the non-nested ones.

Thanks though.

Kevin
 
Kevin,
I see that I can determine if the class is public
or non-public, but I would like to be able to further sub-divide the
non-public modifiers (assembly, family, familyAndAssembly, familyOrAssembly,
private). Is this possible with the .NET 1.1 Reflection API? And just to
clarify, I see I can get this info for nested classes, but I would like it
for non-nested classes too.

For non-nested classes only public and non-public (which you can think
of as private or assembly, there's no difference at the top level)
makes sense. family isn't applicable since there's nothing one level
up that you can inherit from.



Mattias
 
I now see what was wrong in my thinking, but it looks like I need to do a
little reading to understand why that is wrong.

Thanks guys!

Kevin
 
Back
Top