In C#, how can I tell if a property is static? (.Net CF 2.0)

CrashCodes picture CrashCodes · Dec 24, 2008 · Viewed 10.9k times · Source

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
}

Answer

Steven Behnke picture Steven Behnke · Dec 24, 2008

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