views:

554

answers:

2

FieldInfo has an IsStatic member, but PropertyInfo doesn't. I assume I'm just overlooking what I need.

Type type = someObject.GetType();

foreach (PropertyInfo pi in type.GetProperties())
{
   // umm... Not sure how to tell if this property is static
}
+9  A: 

To determine whether a property is static, you must obtain the MethodInfo for the get or set accessor, by calling the GetGetMethod or the GetSetMethod method, and examine its IsStatic property.

http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.aspx

Steven Behnke
Interesting. I never would have guessed there was a GetGetMethod method.
Jim Anderson
+3  A: 

Why not use

type.GetProperties(BindingFlags.Static)
ctacke
Nice! However, in my case I want the non-static which doesn't seem to have a binding flag.
CrashCodes
BindingFlags.Instance
tvanfosson
@tvanfosson Thanks.
CrashCodes