Search code examples
c#reflectioncompact-framework

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


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
}

Solution

  • 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.

    https://learn.microsoft.com/en-us/dotnet/api/system.reflection.propertyinfo