Getting Properties and property values of a sealed class

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
 
G

Gugale at Lincoln

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
 
J

Jon Skeet [C# MVP]

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?
 
G

Gugale at Lincoln

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?
 

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