A base class for attributes that define declarative advice on aspect members. These attributes enable aspects to transform code without requiring explicit calls in BuildAspect(IAspectBuilder<T>).
Inheritance
Implements
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public abstract class DeclarativeAdviceAttribute : Attribute, IAdviceAttributeRemarks
Declarative advice attributes allow you to mark members of an aspect class (methods, properties, fields, events) with attributes that automatically generate advice when the aspect is applied. This is in contrast to imperative advice, where transformations are explicitly added in the BuildAspect(IAspectBuilder<T>) method via AdviserExtensions.
Built-in declarative advice attributes include:
- IntroduceAttribute: Introduces the annotated member into the target type
IntroduceDependencyAttribute(in Metalama.Extensions.DependencyInjection): Introduces a dependency as a property or field
Use the Layer property to control when the advice executes relative to other advice in the same aspect. This is useful when an aspect has multiple pieces of advice that must execute in a specific order.
Constructors
| Name | Description |
|---|---|
| DeclarativeAdviceAttribute() |
Properties
| Name | Description |
|---|---|
| Layer | Gets or sets the name of the aspect layer into which the member will be introduced. The layer must have been defined using the LayersAttribute custom attribute. |
Methods
| Name | Description |
|---|---|
| BuildAdvice(IMemberOrNamedType, string, IAspectBuilder<IDeclaration>) | Builds the aspect, i.e. translates the current declarative advice into a programmatic advice or possibly diagnostics and validators. In case of error, the implementation must report diagnostics and call SkipAspect(). |
| BuildAspectEligibility(IEligibilityBuilder<IDeclaration>, IMemberOrNamedType) | Builds the eligibility of an aspect that contains the current declarative advice. |