Example #1
0
        public static IEnumerable <T> GetCustomAttributes <T>(this System.Type t, AttributeSearchMode attributeSearchMode = AttributeSearchMode.TypeOnly) where T : Attribute
        {
            var customAttributes = t.GetCustomAttributes(typeof(T), attributeSearchMode != AttributeSearchMode.TypeOnly);

            if (customAttributes?.Length == 0 && attributeSearchMode == AttributeSearchMode.InheritanceChainForced && t.BaseType != typeof(object))
            {
                customAttributes = (t.BaseType.GetCustomAttributes <T>(attributeSearchMode)).ToArray();
            }

            return(customAttributes.OfType <T>());
        }
Example #2
0
 public static T GetCustomAttribute <T>(this System.Type t, AttributeSearchMode attributeSearchMode = AttributeSearchMode.TypeOnly) where T : Attribute
 {
     return(t.GetCustomAttributes <T>(attributeSearchMode).SingleOrDefault());
 }