Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Extension method: TAttribute GetCustomAttribute<TAttribute>(this Enum)

  • Declared in: RT.Util.Ut

Declaration

public static TAttribute GetCustomAttribute<TAttribute>(
    this Enum enumValue
)

Summary

Returns the single custom attribute of the specified TAttribute type that is attached to the declaration of the enum value represented by enumValue, or null if there is no such attribute.

Generic type parameters

TAttribute
  • Must derive from: System.Attribute.
The type of the custom attribute to retrieve.

Parameters

this EnumenumValue The enum value for which to retrieve the custom attribute.

Returns

The custom attribute, or null if the enum value does not have a custom attribute of the specified type attached to it. If enumValue does not correspond to a declared enum value, or there is more than one custom attribute of the same type, an exception is thrown.

Exceptions

  • System.ArgumentNullException
    enumValue is null.
  • System.InvalidOperationException
    There is more than one custom attribute of the specified type attached to the enum value declaration.

Remarks

This method uses Ut.GetCustomAttributes<TAttribute>(this Enum), which keeps an internal cache forever.