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:
<ul><li><xref href="Metalama.Framework.Aspects.OverrideFieldOrPropertyAspect.OverrideEnumerableProperty" data-throw-if-not-resolved="false"></xref> for properties returning <xref href="System.Collections.Generic.IEnumerable%601" data-throw-if-not-resolved="false"></xref></li><li><xref href="Metalama.Framework.Aspects.OverrideFieldOrPropertyAspect.OverrideEnumeratorProperty" data-throw-if-not-resolved="false"></xref> for properties returning <xref href="System.Collections.Generic.IEnumerator%601" data-throw-if-not-resolved="false"></xref></li><li><xref href="Metalama.Framework.Aspects.OverrideFieldOrPropertyAspect.OverrideProperty" data-throw-if-not-resolved="false"></xref> for all other properties and fields</li></ul>
If specialized templates are not overridden, <xref href="Metalama.Framework.Aspects.OverrideFieldOrPropertyAspect.OverrideProperty" data-throw-if-not-resolved="false"></xref> is used as the fallback.
</p>
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. |