net472_PropertyGridHelpers.Support_Support_GetFirstCustomAttribute - dparvin/PropertyGridHelpers GitHub Wiki

Support.GetFirstCustomAttribute<T> method

Retrieves the first custom attribute of the specified type applied to the given MemberInfo.

public static T GetFirstCustomAttribute<T>(MemberInfo member)
    where T : Attribute
parameter description
T The type of attribute to retrieve. Must derive from Attribute.
member The member (e.g., property, method, field, type) to inspect for the attribute.

Return Value

An instance of the attribute type T if one is defined on the member; otherwise, null.

Exceptions

exception condition
ArgumentNullException Thrown if member is null.

Remarks

On .NET Framework 3.5, this uses Boolean) internally; on later versions, it uses Boolean).

Examples

Example usage:

var property = typeof(MyClass).GetProperty("MyProperty");
var attr = Support.GetFirstCustomAttribute<AutoCompleteSetupAttribute>(property);
if (attr != null)
{
    // Attribute was found
}

See Also

⚠️ **GitHub.com Fallback** ⚠️