Open sandboxFocus

Method IntroduceFinalizer

IntroduceFinalizer(IAdviser<INamedType>, string, OverrideStrategy, object?, object?)

Introduces a finalizer or overrides the implementation of the existing one. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to a different type than the current one.

Declaration
public static IIntroductionAdviceResult<IMethod> IntroduceFinalizer(this IAdviser<INamedType> adviser, string template, OverrideStrategy whenExists = OverrideStrategy.Default, 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 finalizer. This method must be annotated with TemplateAttribute. This method can have parameters and a return type.

OverrideStrategy whenExists

Determines the implementation strategy when a finalizer is already declared in the target type. The default strategy is to fail with a compile-time error.

object args

An optional object (typically of anonymous type) whose properties map to template method parameters or type parameters. See Sharing state with adviceSharing state with advice for details.

object tags

An optional object (typically of anonymous type) passed to the template and accessible via meta.Tags. See Sharing state with adviceSharing state with advice for details.

Returns
Type Description
IIntroductionAdviceResult<IMethod>

An IIntroductionAdviceResult<T> exposing the introduced or overriding IMethod (finalizer).

See Also