I’m having some trouble getting a static property through reflection in .NET 4.0.
Say for example I have the following classes:
class Foo
{
public static int MyProperty
{
get { return 1234; }
}
}
class Bar : Foo
{
}
Now if I call:
typeof(Foo).GetProperties();
I get the expected list of one property, “MyProperty”. If instead I call:
typeof(Bar).GetProperties();
I get nothing. Unfortunately I’m dealing strictly with values stored as Type data types, so I can’t directly call typeof(Foo).GetProperties().
Thanks for any help!
godwin
You can specify
BindingFlags.FlattenHierarchyto get static properties declared in a base class: