Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

Class Modifiers via Reflection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin Lindsey - 21 May 2004 18:41 GMT
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
AlexS - 21 May 2004 18:46 GMT
Hi, Kevin

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

HTH
Alex

> 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
[quoted text clipped - 7 lines]
>
> Kevin
Kevin Lindsey - 21 May 2004 19:10 GMT
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
Jon Skeet [C# MVP] - 21 May 2004 19:08 GMT
> 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
[quoted text clipped - 3 lines]
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Mattias Sj?gren - 21 May 2004 19:11 GMT
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

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Kevin Lindsey - 21 May 2004 19:32 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.