Skip to content

Instantly share code, notes, and snippets.

@tkouba
Created January 28, 2021 13:25
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 tkouba/56577bf18522a0cf976a1d1d07433427 to your computer and use it in GitHub Desktop.
Save tkouba/56577bf18522a0cf976a1d1d07433427 to your computer and use it in GitHub Desktop.
Simple get attribute value helper extension
public static TValue GetAttributeValue<TAttribute, TValue>(this Type type, Func<TAttribute, TValue> valueSelector) where TAttribute : Attribute
{
var att = type.GetCustomAttributes(typeof(TAttribute), true).FirstOrDefault() as TAttribute;
if (att != null)
{
return valueSelector(att);
}
return default(TValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment