Created
January 28, 2021 13:25
-
-
Save tkouba/56577bf18522a0cf976a1d1d07433427 to your computer and use it in GitHub Desktop.
Simple get attribute value helper extension
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 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