Skip to content

Instantly share code, notes, and snippets.

@munr
Created July 1, 2014 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munr/3544bd7fab6615290561 to your computer and use it in GitHub Desktop.
Save munr/3544bd7fab6615290561 to your computer and use it in GitHub Desktop.
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