Example #1
0
 /// <summary>
 /// get <typeparamref name="TAttribute"/> attribute declared on <paramref name="this"/>
 /// </summary>
 /// <typeparam name="TEnum"></typeparam>
 /// <typeparam name="TAttribute"></typeparam>
 /// <param name="this"></param>
 /// <param name="defaultAttribute"></param>
 /// <returns></returns>
 public static TAttribute?GetAttribute <TEnum, TAttribute>(this TEnum @this, TAttribute?defaultAttribute = default)
     where TEnum : struct, Enum
     where TAttribute : Attribute => TypeCache <TEnum> .GetAttributes <TAttribute>(@this)
 .FirstOrDefault() ?? defaultAttribute;
Example #2
0
 /// <summary>
 /// get <typeparamref name="TAttribute"/> attributes declared on <paramref name="this"/>
 /// </summary>
 /// <typeparam name="TEnum"></typeparam>
 /// <typeparam name="TAttribute"></typeparam>
 /// <param name="this"></param>
 /// <returns></returns>
 public static IEnumerable <TAttribute> GetAttributes <TEnum, TAttribute>(this TEnum @this)
     where TEnum : struct, Enum
     where TAttribute : Attribute => TypeCache <TEnum> .GetAttributes <TAttribute>(@this);