コード例 #1
0
        public static Maybe <TAttribute> GetAttribute <TAttribute>(this Enum value) where TAttribute : Attribute
        {
            Type   type = value.GetType();
            string name = Enum.GetName(type, (object)value);

            return(MaybeExtension.FirstOrNothing <TAttribute>(Enumerable.OfType <TAttribute>((IEnumerable)type.GetField(name).GetCustomAttributes(true))));
        }
コード例 #2
0
 public static Maybe <TAttribute> GetCustomAttribute <TAttribute>(this ICustomAttributeProvider provider, bool inherit = true) where TAttribute : Attribute
 {
     return(MaybeExtension.FirstOrNothing <TAttribute>(GetCustomAttributeExtension.GetCustomAttributes <TAttribute>(provider, inherit)));
 }