Open sandboxFocus

Class SymbolExtensions

Provides extension methods to bridge between the Metalama code model (IDeclaration, IType, etc.) and the Roslyn symbol model (ISymbol).

Inheritance
SymbolExtensions
Namespace: Metalama.Framework.Engine.CodeModel
Assembly: Metalama.Framework.Sdk.dll
Syntax
public static class SymbolExtensions
Remarks

This class enables aspect weavers to convert Metalama declarations to Roslyn symbols for use with the Roslyn API. It also provides methods to go from Roslyn symbols back to Metalama declarations.

Common operations:

Methods

Name Description
GetDeclaration(ICompilation, ISymbol)

Gets the Metalama IDeclaration for a Roslyn ISymbol.

GetExpressionType(ISymbol)

Gets the type of the expression represented by the symbol (e.g., the return type for a method, the field type for a field).

GetOverriddenMember(ISymbol?, bool)

Gets the member that the specified symbol overrides, if any.

GetRootDefinition(IFieldSymbol)

Gets the root definition of a field symbol, handling tuple fields specially.

GetRootDefinition(ISymbol)

Gets the root definition of a symbol (the original definition before any generic substitution).

GetRoslynCompilation(ICompilation)

Gets the underlying Roslyn Compilation from a Metalama ICompilation.

GetSemanticModel(ICompilation, SyntaxTree)

Gets a cached SemanticModel for a syntax tree in the compilation.

GetSymbol(IAssembly, bool)

Gets the Roslyn IAssemblySymbol for a Metalama IAssembly.

GetSymbol(ICompilationElement, bool)

Gets the Roslyn ISymbol for a Metalama declaration.

GetSymbol(IEvent, bool)

Gets the Roslyn IEventSymbol for a Metalama IEvent.

GetSymbol(IField, bool)

Gets the Roslyn IFieldSymbol for a Metalama IField.

GetSymbol(IMethodBase, bool)

Gets the Roslyn IMethodSymbol for a Metalama IMethodBase (method or constructor).

GetSymbol(INamedType, bool)

Gets the Roslyn INamedTypeSymbol for a Metalama INamedType.

GetSymbol(IParameter, bool)

Gets the Roslyn IParameterSymbol for a Metalama IParameter.

GetSymbol(IProperty, bool)

Gets the Roslyn IPropertySymbol for a Metalama IProperty.

GetSymbol(IRef, Compilation, bool)

Gets the Roslyn ISymbol for a declaration reference in a specific compilation.

GetSymbol(IType, bool)

Gets the Roslyn ITypeSymbol for a Metalama IType.

GetSymbol(ITypeParameter, bool)

Gets the Roslyn ITypeParameterSymbol for a Metalama ITypeParameter.

IsDefinitionSafe(ISymbol)

Determines whether a symbol is its own definition, using equality comparison rather than identity.

TryGetDeclaration(ICompilation, ISymbol, out IDeclaration?)

Attempts to get the Metalama IDeclaration for a Roslyn ISymbol.

See Also