MetalamaAPI documentationAspect APIMetalama.​Framework.​AspectsIAspect­Builder
Open sandboxFocus

IAspectBuilder Interface

An object used by the BuildAspect(IAspectBuilder<T>) method of the aspect to provide advice, child aspects and validators, or report diagnostics. This is the weakly-typed variant of the IAspectBuilder<TAspectTarget> interface.

Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
public interface IAspectBuilder


Name Description

Gets an object that allows to create advice, e.g. overriding members, introducing members, or implementing new interfaces.


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


Gets or sets an arbitrary object that is then exposed on the AspectState property of the IAspectInstance interface. While a single instance of an aspect class can be used for several target declarations, the AspectState is specific to the target declaration. If the aspect is inherited, the AspectState must be lama-serializable (ICompileTimeSerializable or default serializable classes).


Gets the cancellation token for the current operation.


Gets a service that allows to report or suppress diagnostics.


Gets a value indicating whether the SkipAspect() method was called.


Gets the name of the layer being built, or null if this is the default (initial) layer. When an aspect has several layers, the BuildAspect(IAspectBuilder<T>) method is called several times. To register aspect layers, add the LayersAttribute custom attribute to the aspect class.


Gets the current IProject, which represents the csproj file and allows to share project-local data.


Gets the declaration to which the aspect was added.


Name Description

Skips the application of the aspect to the code. Any provided advice and child aspects are ignored, but provided diagnostics are preserved. In multi-layer aspects, the next layers of the aspect are skipped.


Returns a copy of the current IAspectBuilder, for use in the current execution context, but for a different Target declaration.

Extension Methods

DependencyInjectionExtensions.TryIntroduceDependency(IAspectBuilder, DependencyProperties, out IFieldOrProperty)