IntroduceMethod(IAdviser<INamedType>, string, IntroductionScope, OverrideStrategy, Action<IMethodBuilder>?, object?, object?)
Introduces a new method or overrides the implementation of the existing one. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.
Declaration
public static IIntroductionAdviceResult<IMethod> IntroduceMethod(this IAdviser<INamedType> adviser, string template, IntroductionScope scope = IntroductionScope.Default, OverrideStrategy whenExists = OverrideStrategy.Default, Action<IMethodBuilder>? buildMethod = null, object? args = null, object? tags = null)
Parameters
Type | Name | Description |
---|---|---|
IAdviser<INamedType> | adviser | An adviser for a named type. |
string | template | Name of the method of the aspect class that will be used as a template for the introduced method. This method must be annotated with TemplateAttribute. This method can have parameters and a return type. The actual parameters and return type of the introduced method can be modified using the IMethodBuilder returned by this method. |
IntroductionScope | scope | Determines the scope (e.g. Instance or Static) of the introduced method. The default scope depends on the scope of the template method. If the method is static, the introduced method is static. However, if the template method is non-static, then the introduced method copies of the scope of the target declaration of the aspect. |
OverrideStrategy | whenExists | Determines the implementation strategy when a method of the same name and signature is already declared in the target type. The default strategy is to fail with a compile-time error. |
Action<IMethodBuilder> | buildMethod | |
object | args | An object (typically of anonymous type) whose properties map to parameters or type parameters of the template methods. |
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<IMethod> | An IMethodBuilder that allows to modify the name or signature, or to add custom attributes. |