Marks a member in an aspect class to be introduced (added) to the target type.
Namespace: Metalama.Framework.Aspects
Assembly: Metalama.Framework.dll
Syntax
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event)]
public sealed class IntroduceAttribute : DeclarativeAdviceAttribute, ITemplateAttribute, IAdviceAttributeRemarks
This attribute enables declarative member introduction, the simplest way to add members through aspects. When applied to a method, property, field, or event in an aspect class, that member is automatically introduced into the target type when the aspect is applied.
The introduced member is based on a T# template - compile-time logic executes to generate the run-time code. Properties like Name, Accessibility, and IsVirtual allow you to customize the introduced member's characteristics. When not set, these properties default to the values from the template member.
Use WhenExists to control behavior when a member with the same name already exists in the target type. The default is Fail, which reports an error.
For programmatic member introduction with more control, use IntroduceMethod(IAdviser<INamedType>, string, IntroductionScope, OverrideStrategy, Action<IMethodBuilder>?, object?, object?), IntroduceProperty(IAdviser<INamedType>, string, IntroductionScope, OverrideStrategy, Action<IPropertyBuilder>?, object?), IntroduceField(IAdviser<INamedType>, string, IntroductionScope, OverrideStrategy, Action<IFieldBuilder>?, object?), or IntroduceEvent(IAdviser<INamedType>, string, IntroductionScope, OverrideStrategy, Action<IEventBuilder>?, object?) in the BuildAspect(IAspectBuilder<T>) method.
Constructors
| Name | Description |
|---|---|
| IntroduceAttribute() |
Properties
| Name | Description |
|---|---|
| Accessibility | |
| IsRequired | |
| IsSealed | |
| IsVirtual | |
| Name | |
| Scope | |
| WhenExists | Gets or sets the strategy to use when a member with the same name already exists in the target type. |
| WhenInherited | Gets or sets the implementation strategy (like Override, Fail or Ignore) when the member is already declared in a parent class of the target type. The default value is Fail. |
Methods
| Name | Description |
|---|---|
| BuildAdvice(IMemberOrNamedType, string, IAspectBuilder<IDeclaration>) | Builds the aspect, i.e. translates the current declarative advice into a programmatic advice or possibly diagnostics and validators. In case of error, the implementation must report diagnostics and call SkipAspect(). |
| BuildAspectEligibility(IEligibilityBuilder<IDeclaration>, IMemberOrNamedType) | Builds the eligibility of an aspect that contains the current declarative advice. |