Class AttributeDataExtensions
- Namespace
- Albatross.CodeAnalysis
- Assembly
- Albatross.CodeAnalysis.dll
Provides extension methods for working with attributes on Roslyn symbols.
public static class AttributeDataExtensions
- Inheritance
-
AttributeDataExtensions
- Inherited Members
Methods
HasAttribute(ISymbol, INamedTypeSymbol?)
Determines whether a symbol has the specified attribute applied to it.
public static bool HasAttribute(this ISymbol symbol, INamedTypeSymbol? targetAttribute)
Parameters
symbolISymbolThe symbol to check.
targetAttributeINamedTypeSymbolThe attribute type to look for.
Returns
- bool
True if the symbol has the attribute; otherwise, false.
HasAttributeWithBaseType(ISymbol, INamedTypeSymbol?)
Determines whether a symbol has any attribute whose class derives from the specified base type.
public static bool HasAttributeWithBaseType(this ISymbol symbol, INamedTypeSymbol? baseType)
Parameters
symbolISymbolThe symbol to check.
baseTypeINamedTypeSymbolThe base type to check for in attribute class hierarchies.
Returns
- bool
True if the symbol has an attribute with the specified base type; otherwise, false.
HasAttributeWithConstructorArguments(ISymbol, INamedTypeSymbol?, params INamedTypeSymbol[])
Determines whether a symbol has the specified attribute with constructor arguments matching the given parameter types.
public static bool HasAttributeWithConstructorArguments(this ISymbol symbol, INamedTypeSymbol? targetAtribute, params INamedTypeSymbol[] parameters)
Parameters
symbolISymbolThe symbol to check.
targetAtributeINamedTypeSymbolThe attribute type to look for.
parametersINamedTypeSymbol[]The expected constructor parameter types.
Returns
- bool
True if the symbol has the attribute with matching constructor arguments; otherwise, false.
TryGetAttribute(ISymbol, INamedTypeSymbol?, out AttributeData?)
Attempts to retrieve the specified attribute from a symbol.
public static bool TryGetAttribute(this ISymbol symbol, INamedTypeSymbol? targetAttribute, out AttributeData? attributeData)
Parameters
symbolISymbolThe symbol to check.
targetAttributeINamedTypeSymbolThe attribute type to look for.
attributeDataAttributeDataWhen this method returns true, contains the attribute data; otherwise, null.
Returns
- bool
True if the attribute was found; otherwise, false.
TryGetNamedArgument(AttributeData, string, out TypedConstant)
Attempts to retrieve a named argument value from an attribute.
public static bool TryGetNamedArgument(this AttributeData attributeData, string name, out TypedConstant result)
Parameters
attributeDataAttributeDataThe attribute data to query.
namestringThe name of the argument to retrieve.
resultTypedConstantWhen this method returns true, contains the typed constant value; otherwise, an empty TypedConstant.
Returns
- bool
True if the named argument was found; otherwise, false.