Defines an aspect weaver that applies low-level transformations to Roslyn compilations using the Roslyn API directly. Aspect weavers bypass the standard BuildAspect(IAspectBuilder<T>) method and provide full control over C# code transformations. Implementations must be public, have a default constructor, and be annotated with the MetalamaPlugInAttribute custom attribute.
Namespace: Metalama.Framework.Engine.AspectWeavers
Assembly: Metalama.Framework.Sdk.dll
Syntax
[CompileTime]
public interface IAspectWeaver : IAspectDriverRemarks
Aspect weavers enable arbitrary C# code transformations that are not possible with the high-level IAspectBuilder advice API. They operate at the Roslyn syntax tree level and have direct access to the Compilation.
To create an aspect weaver:
- Reference the
Metalama.Framework.Sdkpackage withPrivateAssets="all". - Create a class implementing IAspectWeaver and annotate it with MetalamaPlugInAttribute.
- Create an aspect class and annotate it with RequireAspectWeaverAttribute pointing to the weaver type.
- Implement the TransformAsync(AspectWeaverContext) method to perform the transformations.
Warning: Weaver-based aspects are significantly more complex to implement, have worse IDE integration, and have a significant performance impact when many are in use. Prefer using the standard IAspect<T> approach when possible.
Each weaver is invoked once per project, regardless of the number of aspect instances. The AspectInstances property provides the list of all aspect instances to process.
Methods
| Name | Description |
|---|---|
| TransformAsync(AspectWeaverContext) | Transforms a Roslyn compilation according to the aspects being woven. |