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. [Edit]

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. [Edit]
attributeType
The Type of the custom attribute for which to check. [Edit]

Returns

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

Exceptions

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

Remarks

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

Requirements

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