Represents an annotation - an arbitrary serializable object that aspects can attach to declarations to communicate information to other aspects or subsequent compilation phases.
Namespace: Metalama.Framework.Code
Assembly: Metalama.Framework.dll
Syntax
public interface IAnnotation<in T> : IAnnotation, ICompileTimeSerializable where T : class, IDeclarationType Parameters
| Name | Description |
|---|---|
| T | The type of declarations to which the annotation can be added. |
Remarks
Annotations provide a mechanism for aspects to store and share custom metadata on declarations. Common use cases include:
- Inter-aspect communication: One aspect adds an annotation that other aspects can query to coordinate behavior
- Code generation metadata: Store configuration or contextual information that template code needs during code generation
- Aspect coordination: Mark declarations with flags or data that influence how subsequent aspects process them
Adding annotations: Use AddAnnotation<TDeclaration>(IAdviser<TDeclaration>, IAnnotation<TDeclaration>, bool) in your aspect's BuildAspect(IAspectBuilder<T>) method to attach an annotation to a declaration.
Retrieving annotations: Call GetAnnotations<TAnnotation>() via Enhancements<T>(T) to retrieve annotations from a declaration.
Serialization: Annotations must be compile-time serializable (implement ICompileTimeSerializable) as they may be persisted and accessed across project boundaries.
Design-time limitation: At design time (in the IDE), Metalama performs partial compilations that only include the inheritance closure of modified files. Aspects targeting declarations outside of this partial compilation do not execute, so their annotations are not added and cannot be queried. This limitation does not apply at full compile time when all aspects execute.