Mono Class Library: System.Attribute Overview | Members

System.Attribute.GetCustomAttribute Method

Returns an instance of a specified custom attribute if a single instance of the attribute is in the metadata for the specified member.

public static Attribute GetCustomAttribute (System.Reflection.MemberInfo element, Type attributeType)

Parameters

element
An instance of a type derived from System.Reflection.MemberInfo that describes a type member.
attributeType
The Type of the custom attribute for which to check.

Returns

The single instance of Attribute of type attributeType that is applied to element. Returns null if the specified attribute was not found.

Exceptions

TypeReason
ArgumentNullExceptionelement or attributeType is null.
ArgumentExceptionattributeType is not a type derived from Attribute.
NotSupportedExceptionelement does not represent a constructor, method, property, event, type, or field member.
System.Reflection.AmbiguousMatchExceptionMore than one instance of the specified custom attribute was found.

Remarks

Note: If multiple instances of attributeType can be applied to element, use Attribute.GetCustomAttributes(System.Reflection.MemberInfo, Type).

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0