Open sandboxFocus

Class meta

The entry point for the meta model, which can be used in templates to inspect the target code or access other features of the template language.

Inheritance
meta
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public static class meta

Properties

Name Description
AspectInstance

Gets the current IAspectInstance, which gives access to the Predecessors and the SecondaryInstances of the current aspect.

Base

Gets a dynamic object that must be used to get access to instance members of the instance (e.g. meta.Base.MyMethod()). The Base property exposes the state of the target type as it is before the application of the current aspect layer. It corresponds to InvokerOptions.Default. To access the final layer, use This. To access static members, use BaseType.

BaseType

Gets a dynamic object that must be used to get access to static members of the type (e.g. meta.BaseStatic.MyStaticMethod()). The BaseType property exposes the state of the target type as it is before the application of the current aspect layer. It corresponds to InvokerOptions.Default. To access the final layer, use ThisType. To access instance members, use Base.

Tags

Gets the dictionary of tags that were passed to the IAdviceFactory method by the BuildAspect(IAspectBuilder<T>) method.

Target

Gets access to the declaration being overridden or introduced.

This

Gets a dynamic object that represents an instance of the target type. It can be used as a value (e.g. as a method argument) or can be used to get access to instance members of the instance (e.g. meta.This.MyMethod()). The This property exposes the state of the target type as it is after the application of all aspects. If the member is virtual, a virtual call is performed, therefore the implementation on the child type (possibly with all applied aspects) is performed. It corresponds to InvokerOptions.Final. To access the prior layer (or the base type, if there is no prior layer), use Base. To access static members, use ThisType.

ThisType

Gets a dynamic object that must be used to get access to static members of the type (e.g. meta.ThisStatic.MyStaticMethod()). The ThisType property exposes the state of the target type as it is after the application of all aspects. It corresponds to InvokerOptions.Final. To access the prior layer (or the base type, if there is no prior layer), use BaseType. To access instance members, use This.

Methods

Name Description
Cast(IType, dynamic?)

Generates the cast syntax for the specified type.

CompileTime<T>(T?)

Coerces an expression to be interpreted as compile time. This is typically used to coerce expressions that can be either run-time or compile-time, such as a literal. Since ambiguous expressions are interpreted as run-time by default, this method allows to change that behavior.

DebugBreak()

Requests the debugger to break, if any debugger is attached to the current process.

Default(IType)

Generates the default(T) syntax for the specified type.

Default(SpecialType)

Generates the default(T) syntax for the specified type.

Default(Type)

Generates the default(T) syntax for the specified type.

DefineLocalVariable(string, IExpression)
DefineLocalVariable(string, IType)
DefineLocalVariable(string, IType, IExpression?)
DefineLocalVariable(string, IType, dynamic)
DefineLocalVariable(string, dynamic)
DefineLocalVariable(string, Type)
DefineLocalVariable(string, Type, IExpression?)
DefineLocalVariable(string, Type, dynamic)
InsertComment(params string?[])

Injects a comment to the target code.

InsertStatement(IExpression)

Inserts a statement into the target code, where the statement is given as an IExpression. Note that not all expressions can be used as statements.

InsertStatement(IStatement)

Inserts a statement into the target code, where the statement is given as an IStatement.

InsertStatement(string)

Inserts a statement into the target code, where the statement is given as a string. Calling this overload is equivalent to calling the InsertStatement(IStatement) overload with the result of the Parse(string) method.

InvokeTemplate(TemplateInvocation, object?)

Calls another template method.

InvokeTemplate(string, ITemplateProvider?, object?)

Calls another template method. This overload accepts an ITemplateProvider.

InvokeTemplate(string, TemplateProvider, object?)

Calls another template method. This overload accepts a TemplateProvider.

Proceed()

Invokes the logic that has been overwritten. For instance, in an OverrideMethodAspect, calling Proceed() invokes the method being overridden. Note that the way how the logic is invoked (as a method call or inlining) is considered an implementation detail.

ProceedAsync()

Synonym to Proceed(), but the return type is exposed as a Task<dynamic?>. Only use this method when the return type of the method or accessor is task-like. Note that the actual return type of the overridden method or accessor is the one of the overwritten semantic, so it can be a void Task, a ValueType, or any other type.

ProceedAsyncEnumerable()
ProceedAsyncEnumerator()
ProceedEnumerable()

Synonym to Proceed(), but the return type is exposed as a IEnumerable<dynamic?>.

ProceedEnumerator()

Synonym to Proceed(), but the return type is exposed as a IEnumerator<dynamic?>.

Return()

Inserts a return; statement into the target code.

Return(dynamic?)

Inserts a return statement into the target code. This can be used to return a value from void-returning template methods.

RunTime<T>(T?)

Converts a compile-value into run-time value by serializing the compile-time value into a some syntax that will evaluate, at run time, to the same value as at compile time.

See Also