System.Reflection.CustomAttributeExtensions.GetCustomAttribute Method

Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.

Syntax

public static Attribute GetCustomAttribute (this MemberInfo element, Type attributeType, bool inherit)

Parameters

element
The member to inspect.
attributeType
The type of attribute to search for.
inherit
true to inspect the ancestors of element; otherwise, false.

Returns

A custom attribute that matches attributeType, or null if no such attribute is found.

Remarks

Use the CustomAttributeExtensions.GetCustomAttributes(Assembly, Type) extension method if you expect more than one value to be returned, or System.Reflection.AmbiguousMatchException will be thrown.

Requirements

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 4.0.0.0