The base interface for all aspects. Aspects are compile-time components that transform, validate, or enhance code.
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[RunTimeOrCompileTime]
public interface IAspect : ICompileTimeSerializable, ITemplateProviderRemarks
Aspect classes should not implement this non-generic interface directly. Instead, implement the generic variant IAspect<T> or derive from convenience base classes like Aspect, TypeAspect, MethodAspect, or other specialized aspect base classes.
What aspects can do:
- Transform code: Override methods, introduce new members, implement interfaces
- Report and suppress diagnostics: Emit errors, warnings, information messages; suppress compiler diagnostics
- Validate code: Perform advanced validations on target declarations and their references
- Add child aspects: Programmatically apply additional aspects to other declarations
- Define eligibility: Specify which declarations the aspect can legally target
- Customize IDE experience: Control how the aspect appears in code refactoring menus
- Execute in layers: Use LayersAttribute to split aspect implementation into multiple ordered execution phases
Immutability: Aspects must be designed as immutable classes. Never store target-specific state in aspect fields because the same aspect instance may be reused across multiple target declarations in inheritance or cross-project scenarios. See Understanding the aspect framework designUnderstanding the aspect framework design for more details.