Table of Contents

Class AttributeHelper

Namespace
Ecng.Common
Assembly
Ecng.Common.dll

Provides helper methods for working with custom attributes including caching support.

public static class AttributeHelper
Inheritance
AttributeHelper
Inherited Members

Properties

CacheEnabled

Gets or sets a value indicating whether attribute caching is enabled.

public static bool CacheEnabled { get; set; }

Property Value

bool

Methods

ClearCache()

Clears the internal attribute cache.

public static void ClearCache()

GetAttribute<TAttribute>(ICustomAttributeProvider, bool)

Retrieves the first custom attribute of the specified type, optionally searching the ancestors. If caching is enabled, the attribute is stored and reused.

public static TAttribute GetAttribute<TAttribute>(this ICustomAttributeProvider provider, bool inherit = true) where TAttribute : Attribute

Parameters

provider ICustomAttributeProvider

The attribute provider to search.

inherit bool

true to inspect the ancestors of the provider; otherwise, false.

Returns

TAttribute

The first attribute of type TAttribute found on the provider; otherwise, null.

Type Parameters

TAttribute

The type of the custom attribute to retrieve.

GetAttributes(ICustomAttributeProvider, bool)

Retrieves all custom attributes from the provider, optionally searching the ancestors.

public static IEnumerable<Attribute> GetAttributes(this ICustomAttributeProvider provider, bool inherit = true)

Parameters

provider ICustomAttributeProvider

The attribute provider to search.

inherit bool

true to inspect the ancestors of the provider; otherwise, false.

Returns

IEnumerable<Attribute>

An enumerable collection of custom attributes.

GetAttributes<TAttribute>(ICustomAttributeProvider, bool)

Retrieves all custom attributes of the specified type from the provider, optionally searching the ancestors.

public static IEnumerable<TAttribute> GetAttributes<TAttribute>(this ICustomAttributeProvider provider, bool inherit = true) where TAttribute : Attribute

Parameters

provider ICustomAttributeProvider

The attribute provider to search.

inherit bool

true to inspect the ancestors of the provider; otherwise, false.

Returns

IEnumerable<TAttribute>

An enumerable collection of attributes of type TAttribute.

Type Parameters

TAttribute

The type of the custom attributes to retrieve.

IsBrowsable(ICustomAttributeProvider)

Determines whether the provider is marked as browsable via the BrowsableAttribute.

public static bool IsBrowsable(this ICustomAttributeProvider provider)

Parameters

provider ICustomAttributeProvider

The attribute provider to check.

Returns

bool

true if the BrowsableAttribute is not present or its Browsable property is true; otherwise, false.

IsObsolete(ICustomAttributeProvider)

Determines whether the provider is marked with the ObsoleteAttribute.

public static bool IsObsolete(this ICustomAttributeProvider provider)

Parameters

provider ICustomAttributeProvider

The attribute provider to check.

Returns

bool

true if the provider has the ObsoleteAttribute; otherwise, false.