AttributeHelper
Provides helper methods for working with custom attributes including caching support.
Properties
public static bool CacheEnabled { get; set; }
value = AttributeHelper.CacheEnabled
AttributeHelper.CacheEnabled = value
Gets or sets a value indicating whether attribute caching is enabled.
Methods
public static void ClearCache()
AttributeHelper.ClearCache()
Clears the internal attribute cache.
public static IEnumerable<Attribute> GetAttributes(ICustomAttributeProvider provider, bool inherit)
result = AttributeHelper.GetAttributes(provider, inherit)
Retrieves all custom attributes from the provider, optionally searching the ancestors.
- provider
- The attribute provider to search.
- inherit
- true to inspect the ancestors of the provider; otherwise, false.
Returns: An enumerable collection of custom attributes.
public static IEnumerable<TAttribute> GetAttributes<TAttribute>(ICustomAttributeProvider provider, bool inherit)
result = AttributeHelper.GetAttributes(provider, inherit)
Retrieves all custom attributes of the specified type from the provider, optionally searching the ancestors.
- provider
- The attribute provider to search.
- inherit
- true to inspect the ancestors of the provider; otherwise, false.
Returns: An enumerable collection of attributes of type .
public static TAttribute GetAttribute<TAttribute>(ICustomAttributeProvider provider, bool inherit)
result = AttributeHelper.GetAttribute(provider, inherit)
Retrieves the first custom attribute of the specified type, optionally searching the ancestors. If caching is enabled, the attribute is stored and reused.
- provider
- The attribute provider to search.
- inherit
- true to inspect the ancestors of the provider; otherwise, false.
Returns: The first attribute of type found on the provider; otherwise, null.
public static bool IsBrowsable(ICustomAttributeProvider provider)
result = AttributeHelper.IsBrowsable(provider)
Determines whether the provider is marked as browsable via the BrowsableAttribute.
- provider
- The attribute provider to check.
Returns: true if the BrowsableAttribute is not present or its Browsable property is true; otherwise, false.
public static bool IsObsolete(ICustomAttributeProvider provider)
result = AttributeHelper.IsObsolete(provider)
Determines whether the provider is marked with the ObsoleteAttribute.
- provider
- The attribute provider to check.
Returns: true if the provider has the ObsoleteAttribute; otherwise, false.