BuildAspect(IAspectBuilder<INamedType>)
Defines the aspect implementation by adding advice, child aspects, and validators to the target declaration.
Declaration
public virtual void BuildAspect(IAspectBuilder<INamedType> builder)Parameters
| Type | Name | Description |
|---|---|---|
| IAspectBuilder<INamedType> | builder | An object that provides methods to add transformations (advice), apply child aspects, and register validators. |
Implements
Remarks
This method is called at compile time for each target declaration where the aspect is applied.
Use the builder to add code transformations via extension methods from AdviserExtensions
such as builder.Override(), builder.IntroduceMethod(), and others.
Immutability requirement: Aspects must be designed as immutable classes. Never store target-specific state in aspect fields from this method because, in scenarios involving inherited aspects or cross-project validators, the same aspect instance is reused across multiple target declarations. To pass state to templates, use Tags or compile-time template parameters. See Sharing state with adviceSharing state with advice for details.
Multiple invocations: If the aspect class is annotated with LayersAttribute, this method is called multiple times (once per layer) for the same target declaration. Access Layer to determine which layer is currently being built.
Template provision: As aspects implement ITemplateProvider, you can define template methods (annotated with TemplateAttribute) that are used by advice to generate transformed code.