SymbolAttributeExtensions Class
internal static class SymbolAttributeExtensionsNo documentation is available.
Methods
| Name | Description |
|---|---|
| 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
symbolISymbol- The symbol whose attributes are inspected.
attributeTypeITypeSymbol?- The type of the attribute to look for. When
null, no attribute is returned. inheritsbool- When
true, an attribute also matches when its class derives fromattributeType. Whenfalse, the attribute class must be exactlyattributeType. This parameter is ignored whenattributeTypeis sealed, as no other class can derive from it. Note this is unrelated to theinheritparameter ofAttribute.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
symbolISymbol- The symbol whose attributes are inspected.
attributeTypeITypeSymbol?- The type of the attribute to look for. When
null, no attribute is returned. inheritsbool- When
true, an attribute also matches when its class derives fromattributeType. Whenfalse, the attribute class must be exactlyattributeType. This parameter is ignored whenattributeTypeis sealed, as no other class can derive from it. Note this is unrelated to theinheritparameter ofAttribute.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
symbolISymbol- The symbol whose attributes are inspected.
attributeTypeITypeSymbol?- The type of the attribute to look for. When
null, the method returnsfalse. inheritsbool- When
true, an attribute also matches when its class derives fromattributeType. Whenfalse, the attribute class must be exactlyattributeType. This parameter is ignored whenattributeTypeis sealed, as no other class can derive from it. Note this is unrelated to theinheritparameter ofAttribute.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.