A base aspect that overrides the implementation of a field or property using T# template properties.
Implements
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
public abstract class OverrideFieldOrPropertyAspect : FieldOrPropertyAspect, IAspect<IFieldOrProperty>, IAspect, ICompileTimeSerializable, ITemplateProvider, IEligible<IFieldOrProperty>Remarks
This class simplifies creating aspects that override field or property behavior. Derived classes must implement the
OverrideProperty template property, which is a T# template that executes at compile-time to generate
the new accessor implementations. Use meta.Target.FieldOrProperty.Value within the template to access or modify
the underlying field or property value, and meta.Target.FieldOrProperty to access metadata.
When applied to a field or auto-property, a backing field is automatically created to store the value, similar to how auto-properties are transformed.
The aspect automatically selects the appropriate template based on the property's return type:
- OverrideEnumerableProperty for properties returning IEnumerable<T>
- OverrideEnumeratorProperty for properties returning IEnumerator<T>
- OverrideProperty for all other properties and fields
For overriding multiple fields or properties from a single aspect, or for separate control over getter and setter templates,
use OverrideAccessors(IAdviser<IFieldOrProperty>, in GetterTemplateSelector, string?, object?, object?) or
Override(IAdviser<IFieldOrProperty>, string, object?) from your BuildAspect method instead of deriving from this class.
Constructors
| Name | Description |
|---|---|
| OverrideFieldOrPropertyAspect() |
Properties
| Name | Description |
|---|---|
| OverrideEnumerableProperty | Template property for overriding properties returning IEnumerable<T>. |
| OverrideEnumeratorProperty | Template property for overriding properties returning IEnumerator<T>. |
| OverrideProperty | The default template property for overriding field or property accessors. |
Methods
| Name | Description |
|---|---|
| BuildAspect(IAspectBuilder<IFieldOrProperty>) | Defines the aspect implementation by adding advice, child aspects, and validators to the target declaration. |
| BuildEligibility(IEligibilityBuilder<IFieldOrProperty>) | Configures the eligibility of the aspect or attribute by defining rules that determine which declarations the aspect can be applied to. |