Class AttributeUtil
Provides utility methods for retrieving custom Attribute.
public static class AttributeUtil
- Inheritance
-
AttributeUtil
- Inherited Members
Methods
GetCustomAttribute<T>(Type)
A generic version of GetCustomAttribute(MemberInfo, Type, bool) for Type. Retrieves a custom attribute applied to the type. Parameters specify the type with the custom attribute, the type of the custom attribute to search for. Doesn't look up the element's ancestors for custom attributes.
public static T? GetCustomAttribute<T>(Type type) where T : Attribute
Parameters
typeTypeThe type to which the custom attribute is applied.
Returns
- T
A reference to the single custom attribute of type
Tthat is applied to element, ornullif there is no such attribute.
Type Parameters
TThe type, or a base type, of the custom attribute to search for.
Exceptions
- ArgumentNullException
typeisnull.- AmbiguousMatchException
More than one of the requested attributes was found.
- TypeLoadException
A custom attribute type cannot be loaded.
GetCustomAttribute<T>(Type, bool)
A generic version of GetCustomAttribute(MemberInfo, Type, bool) for Type. Retrieves a custom attribute applied to the type. Parameters specify the type with the custom attribute, the type of the custom attribute to search for, and whether to search ancestors of the type.
public static T? GetCustomAttribute<T>(Type type, bool inherit) where T : Attribute
Parameters
typeTypeThe type to which the custom attribute is applied.
inheritboolIf
true, specifies to also search the ancestors of element for custom attributes.
Returns
- T
A reference to the single custom attribute of type
Tthat is applied to element, ornullif there is no such attribute.
Type Parameters
TThe type, or a base type, of the custom attribute to search for.
Exceptions
- ArgumentNullException
typeisnull.- AmbiguousMatchException
More than one of the requested attributes was found.
- TypeLoadException
A custom attribute type cannot be loaded.