IntroduceConstructor(INamedType, string, OverrideStrategy, Action<IConstructorBuilder>?, object?, object?)
Introduces a new constructor or overrides the implementation of the existing one.
Declaration
IIntroductionAdviceResult<IConstructor> IntroduceConstructor(INamedType targetType, string template, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IConstructorBuilder>? buildConstructor = null, object? args = null, object? tags = null)Parameters
| Type | Name | Description |
|---|---|---|
| INamedType | targetType | The type into which the constructor must be introduced. |
| string | template | Name of the method of the aspect class that will be used as a template for the introduced constructor. This method must be annotated with TemplateAttribute. |
| OverrideStrategy | whenExists | Determines the implementation strategy when a constructor with the same signature is already declared in the target type. The default strategy is to fail with a compile-time error. |
| Action<IConstructorBuilder> | buildConstructor | An optional callback that allows you to configure the introduced constructor, such as changing its accessibility, parameters, or adding custom attributes. |
| object | args | An object (typically of anonymous type) whose properties map to parameters or type parameters of the template method. |
| object | tags | An optional opaque object of anonymous type passed to the template method and exposed under the Tags property of the meta API. |
Returns
| Type | Description |
|---|---|
| IIntroductionAdviceResult<IConstructor> | An IIntroductionAdviceResult<T> representing the result of the advice. The Declaration property provides access to the introduced constructor. |