List all public properties of a Class ?

  • Thread starter Thread starter Cerebrus
  • Start date Start date
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.
 
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.
 
Cerebrus,

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

I hope this helps

Cor
 
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.
 
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'.
 
Back
Top