Getting Properties and property values of a sealed class

  • Thread starter Thread starter Gugale at Lincoln
  • Start date Start date
G

Gugale at Lincoln

I am using a function to get properies and property values of an object
private string[] ObjPropVals(Object o)
{
Type t = o.GetType();
PropertyInfo[] pia = t.GetProperties();
string[] stra = new string[pia.Length];
for(int i=0; i<pia.Length; i++)
{
stra = pia.Name + " " + pia.GetValue(o, null);
}
return stra;
}

I would like to use something similar to get static properties of a sealed
class. Any suggestions?

Thanks
SG
 
I leftout some info. I am talking about the classes you can not create an
instance of (private constructors). How can I get static properties and
propery values of such classes?

Thanks
SG
 
Gugale at Lincoln said:
I leftout some info. I am talking about the classes you can not create an
instance of (private constructors). How can I get static properties and
propery values of such classes?

Use typeof(TypeName) to get a Type, then you can still call
GetProperties. Just pass null as the first parameter to GetValue.

If that doesn't help, could you give us the code you've tried?
 
That helped! Thank you!

Jon Skeet said:
Use typeof(TypeName) to get a Type, then you can still call
GetProperties. Just pass null as the first parameter to GetValue.

If that doesn't help, could you give us the code you've tried?
 
Back
Top