SymbolAttributeExtensions Class

internal static class SymbolAttributeExtensions

No documentation is available.

Methods

NameDescription
GetAttributes(ISymbol, ITypeSymbol?, bool)Gets the attributes applied to symbol that match attributeType. Only the attributes applied to the symbol itself are considered. Unlike Attribute.GetCustomAttributes(inherit: true), the base types of the symbol and the members it overrides are never inspected.
GetFirstAttribute(ISymbol, ITypeSymbol?, bool)Gets the first attribute applied to symbol that matches attributeType. Only the attributes applied to the symbol itself are considered. Unlike Attribute.GetCustomAttributes(inherit: true), the base types of the symbol and the members it overrides are never inspected.
HasAttribute(ISymbol, ITypeSymbol?, bool)Indicates whether symbol has an attribute matching attributeType. Only the attributes applied to the symbol itself are considered. Unlike Attribute.GetCustomAttributes(inherit: true), the base types of the symbol and the members it overrides are never inspected.

GetAttributes(ISymbol, ITypeSymbol?, bool)

Gets the attributes applied to symbol that match attributeType. Only the attributes applied to the symbol itself are considered. Unlike Attribute.GetCustomAttributes(inherit: true), the base types of the symbol and the members it overrides are never inspected.

public static IEnumerable<AttributeData> GetAttributes(this ISymbol symbol, ITypeSymbol? attributeType, bool inherits = true)

Parameters

symbol ISymbol
The symbol whose attributes are inspected.
attributeType ITypeSymbol?
The type of the attribute to look for. When null, no attribute is returned.
inherits bool
When true, an attribute also matches when its class derives from attributeType. When false, the attribute class must be exactly attributeType. This parameter is ignored when attributeType is sealed, as no other class can derive from it. Note this is unrelated to the inherit parameter of Attribute.GetCustomAttributes: it never makes the base types of the symbol or the members it overrides be inspected.

Returns

IEnumerable<AttributeData> The attributes applied to symbol that match attributeType.

GetFirstAttribute(ISymbol, ITypeSymbol?, bool)

Gets the first attribute applied to symbol that matches attributeType. Only the attributes applied to the symbol itself are considered. Unlike Attribute.GetCustomAttributes(inherit: true), the base types of the symbol and the members it overrides are never inspected.

public static AttributeData? GetFirstAttribute(this ISymbol symbol, ITypeSymbol? attributeType, bool inherits = true)

Parameters

symbol ISymbol
The symbol whose attributes are inspected.
attributeType ITypeSymbol?
The type of the attribute to look for. When null, no attribute is returned.
inherits bool
When true, an attribute also matches when its class derives from attributeType. When false, the attribute class must be exactly attributeType. This parameter is ignored when attributeType is sealed, as no other class can derive from it. Note this is unrelated to the inherit parameter of Attribute.GetCustomAttributes: it never makes the base types of the symbol or the members it overrides be inspected.

Returns

AttributeData? The first matching attribute, or null when symbol has no matching attribute.

HasAttribute(ISymbol, ITypeSymbol?, bool)

Indicates whether symbol has an attribute matching attributeType. Only the attributes applied to the symbol itself are considered. Unlike Attribute.GetCustomAttributes(inherit: true), the base types of the symbol and the members it overrides are never inspected.

public static bool HasAttribute(this ISymbol symbol, ITypeSymbol? attributeType, bool inherits = true)

Parameters

symbol ISymbol
The symbol whose attributes are inspected.
attributeType ITypeSymbol?
The type of the attribute to look for. When null, the method returns false.
inherits bool
When true, an attribute also matches when its class derives from attributeType. When false, the attribute class must be exactly attributeType. This parameter is ignored when attributeType is sealed, as no other class can derive from it. Note this is unrelated to the inherit parameter of Attribute.GetCustomAttributes: it never makes the base types of the symbol or the members it overrides be inspected.

Returns

bool true when symbol has a matching attribute; otherwise false.