Table of Contents

Class AttributesExtensions

Namespace
LinqToDB.Extensions
Assembly
linq2db.dll
public static class AttributesExtensions
Inheritance
AttributesExtensions

Methods

GetAttribute<T>(ICustomAttributeProvider, bool)

Retrieves first custom attribute applied to a type or type member. If there are multiple attributes found and inherit set to true, attribute from source preferred.

public static T? GetAttribute<T>(this ICustomAttributeProvider source, bool inherit = true) where T : Attribute

Parameters

source ICustomAttributeProvider

An attribute owner.

inherit bool

When true, look up the hierarchy chain for the inherited custom attribute.

Returns

T

A reference to the first custom attribute of type T that is applied to element, or null if there is no such attribute.

Type Parameters

T

The type of attribute to search for. Only attributes that are assignable to this type are returned.

GetAttributes<T>(ICustomAttributeProvider, bool)

Returns a list of custom attributes applied to a type or type member. If there are multiple attributes found and inherit set to true, attributes ordered from current to base type in inheritance hierarchy.

public static T[] GetAttributes<T>(this ICustomAttributeProvider source, bool inherit = true) where T : Attribute

Parameters

source ICustomAttributeProvider

An attribute owner.

inherit bool

When true, look up the hierarchy chain for the inherited custom attribute.

Returns

T[]

A list of custom attributes applied to this type, or a list with zero (0) elements if no attributes have been applied.

Type Parameters

T

The type of attribute to search for. Only attributes that are assignable to this type are returned.

HasAttribute<T>(ICustomAttributeProvider, bool)

Check if attribute that implements T type exists on source.

public static bool HasAttribute<T>(this ICustomAttributeProvider source, bool inherit = true) where T : Attribute

Parameters

source ICustomAttributeProvider

An attribute owner.

inherit bool

When true, look up the hierarchy chain for the inherited custom attribute.

Returns

bool

Returns true if at least one attribute found.

Type Parameters

T

The type of attribute to search for. Only attributes that are assignable to this type are covered.