Created
April 20, 2012 21:11
-
-
Save jeffwilcox/2431936 to your computer and use it in GitHub Desktop.
Is a PropertyInfo a static property?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool IsStatic(this PropertyInfo propertyInfo) | |
{ | |
return ((propertyInfo.CanRead && propertyInfo.GetMethod.IsStatic) || | |
(propertyInfo.CanWrite && propertyInfo.SetMethod.IsStatic)); | |
} | |
// So a replacement for getting private and public non-static properties in a type... | |
public static bool IsStatic(this PropertyInfo propertyInfo) | |
{ | |
return ((propertyInfo.CanRead && propertyInfo.GetMethod.IsStatic) || | |
(propertyInfo.CanWrite && propertyInfo.SetMethod.IsStatic)); | |
} | |
public static PropertyInfo[] GetPublicAndNonPublicInstanceProperties(this Type type) | |
{ | |
var list = new List<PropertyInfo>(); | |
var props = type.GetTypeInfo().DeclaredProperties; | |
foreach (var prop in props) | |
{ | |
if (!prop.IsStatic()) | |
{ | |
list.Add(prop); | |
} | |
} | |
return list.ToArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment