Table of Contents

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

symbol ISymbol

The symbol to check.

targetAttribute INamedTypeSymbol

The 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

symbol ISymbol

The symbol to check.

baseType INamedTypeSymbol

The 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

symbol ISymbol

The symbol to check.

targetAtribute INamedTypeSymbol

The attribute type to look for.

parameters INamedTypeSymbol[]

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

symbol ISymbol

The symbol to check.

targetAttribute INamedTypeSymbol

The attribute type to look for.

attributeData AttributeData

When 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

attributeData AttributeData

The attribute data to query.

name string

The name of the argument to retrieve.

result TypedConstant

When this method returns true, contains the typed constant value; otherwise, an empty TypedConstant.

Returns

bool

True if the named argument was found; otherwise, false.