Home All Groups Group Topic Archive Search About

List all public properties of a Class ?

Author
26 Feb 2006 6:38 AM
Cerebrus
Hi all,

Is there any way to get a list of all the Public properties of a Class
?

Something like the GetNames() function returns a list of all the items
in an Enumeration.

As a simple example, let's take the SystemIcons Class. Say, I want to
get a list of all it's Public Properties.

Thanks in advance,

Regards,

Cerebrus.

Author
26 Feb 2006 9:21 AM
CMM
Look at System.Reflection
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemreflection.asp

--
-C. Moya
www.cmoya.com

Show quoteHide quote
"Cerebrus" <zorg***@sify.com> wrote in message
news:1140935893.808675.284440@j33g2000cwa.googlegroups.com...
> Hi all,
>
> Is there any way to get a list of all the Public properties of a Class
> ?
>
> Something like the GetNames() function returns a list of all the items
> in an Enumeration.
>
> As a simple example, let's take the SystemIcons Class. Say, I want to
> get a list of all it's Public Properties.
>
> Thanks in advance,
>
> Regards,
>
> Cerebrus.
>
Author
26 Feb 2006 11:16 AM
Cerebrus
Err... could you perhaps point me to a tutorial or an example on the
subject.

I'm a bit weak on the subject of Reflection ! ;-)

Regards,

Cerebrus.
Author
26 Feb 2006 11:35 AM
Cerebrus
I think I got the answer to my original question : (For the benefit of
anyone who doesn't know)

Dim myType As Type = GetType(System.Drawing.SystemIcons)
Dim myProps() As PropertyInfo =
myType.GetProperties(BindingFlags.Public Or BindingFlags.Static)
Dim myProp As PropertyInfo
For Each myProp In myProps
   Console.WriteLine("Name: {0}, Type: {1}", myProp.Name,
myProp.PropertyType)
Next

Regards,

Cerebrus.
Author
26 Feb 2006 11:30 AM
Cor Ligthert [MVP]
Cerebrus,

Did you already look at the objectbrowser, View-> ObjectBrowser and look in
the (standard) right pane.

I hope this helps

Cor
Author
26 Feb 2006 1:01 PM
Herfried K. Wagner [MVP]
"Cerebrus" <zorg***@sify.com> schrieb:
> Is there any way to get a list of all the Public properties of a Class
> ?
>
> Something like the GetNames() function returns a list of all the items
> in an Enumeration.
>
> As a simple example, let's take the SystemIcons Class. Say, I want to
> get a list of all it's Public Properties.

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/ac8f8da74ab352f4>

Note the 'BindingFlags'.  In order to get the shared properties you need to
specify 'BindingFlags.Static' instead of 'BindingFlags.Instance'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>