Created
July 1, 2014 19:24
-
-
Save munr/3544bd7fab6615290561 to your computer and use it in GitHub Desktop.
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 class ReflectionExtensions | |
{ | |
public static T GetCustomAttribute<T>(this PropertyInfo pi) | |
{ | |
var attrs = pi.GetCustomAttributes(typeof(T), true); | |
return (T)attrs.FirstOrDefault(); | |
} | |
public static object GetValue(this PropertyInfo pi, object o) | |
{ | |
return o.GetType().GetProperty(pi.Name).GetValue(o, null); | |
} | |
public static void SetValue(this PropertyInfo pi, object o, object value) | |
{ | |
pi.SetValue(o, value, null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment