List all public properties of a Class ?

C

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.
 
C

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.
 
C

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
 
C

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.
 
H

Herfried K. Wagner [MVP]

Cerebrus said:
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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top