Open sandboxFocus

Interface IAspect

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, ITemplateProvider
Remarks

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:

  1. Transform code: Override methods, introduce new members, implement interfaces
  2. Report and suppress diagnostics: Emit errors, warnings, information messages; suppress compiler diagnostics
  3. Validate code: Perform advanced validations on target declarations and their references
  4. Add child aspects: Programmatically apply additional aspects to other declarations
  5. Define eligibility: Specify which declarations the aspect can legally target
  6. Customize IDE experience: Control how the aspect appears in code refactoring menus
  7. 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.

Extension Methods

See Also