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
type
TypeThe type to which the custom attribute is applied.
Returns
- T
A reference to the single custom attribute of type
T
that is applied to element, ornull
if there is no such attribute.
Type Parameters
T
The type, or a base type, of the custom attribute to search for.
Exceptions
- ArgumentNullException
type
isnull
.- 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
type
TypeThe type to which the custom attribute is applied.
inherit
boolIf
true
, specifies to also search the ancestors of element for custom attributes.
Returns
- T
A reference to the single custom attribute of type
T
that is applied to element, ornull
if there is no such attribute.
Type Parameters
T
The type, or a base type, of the custom attribute to search for.
Exceptions
- ArgumentNullException
type
isnull
.- AmbiguousMatchException
More than one of the requested attributes was found.
- TypeLoadException
A custom attribute type cannot be loaded.