Skip to content

Instantly share code, notes, and snippets.

@imgen
Created October 3, 2017 16:06
Show Gist options
  • Save imgen/126763157e61c3055e3da026f7a423a7 to your computer and use it in GitHub Desktop.
Save imgen/126763157e61c3055e3da026f7a423a7 to your computer and use it in GitHub Desktop.
Extensions
public static IEnumerable<PropertyInfo> GetPropertiesWithAttributes<T, TAttr>(this object obj)
{
return GetPropertiesWithAttributes(obj, typeof(T), typeof(TAttr));
}
public static IEnumerable<PropertyInfo> GetPropertiesWithAttributes(this object obj, Type type, Type attrType)
{
return type.GetProperties()
.Where(x => x.GetCustomAttributes(true)
.Any(attr => attr.GetType() == attrType)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment