Open sandboxFocus

Method InterceptMethods

InterceptMethods<TScope>(IAdviser<TScope>, Func<IMethodInterceptionBuilder, IMethodInterception>)

Registers the interception of the uses of methods, described by a delegate.

Declaration
public static void InterceptMethods<TScope>(this IAdviser<TScope> adviser, Func<IMethodInterceptionBuilder, IMethodInterception> build) where TScope : class, IDeclaration
Parameters
Type Name Description
IAdviser<TScope> adviser

An adviser whose target is the scope declaration.

Func<IMethodInterceptionBuilder, IMethodInterception> build

A delegate that receives an IMethodInterceptionBuilder, selects the intercepted methods, chooses how the calls are intercepted, and returns the resulting IMethodInterception, for instance b => b.Type( typeof(Console) ).Methods( "WriteLine" ).RedirectToSynthesizedMethod( nameof(this.Log) ). It is invoked once, before this method returns.

Type Parameters
Name Description
TScope
Exceptions
Type Condition
ArgumentNullException

build is null.

ArgumentException

The delegate returned null, or a value that does not describe a complete interception.

InvalidOperationException

The delegate discarded a value that it created, or the project that executes the registration does not reference the Metalama.Extensions.Interceptors package.

InterceptMethods(ITypeAmender, Func<IMethodInterceptionBuilder, IMethodInterception>)

Registers the interception of the uses of methods, described by a delegate. The scope declaration is the type of the fabric.

Declaration
public static void InterceptMethods(this ITypeAmender amender, Func<IMethodInterceptionBuilder, IMethodInterception> build)
Parameters
Type Name Description
ITypeAmender amender

The amender of a type fabric.

Func<IMethodInterceptionBuilder, IMethodInterception> build

A delegate that describes the interception, as in InterceptMethods<TScope>(IAdviser<TScope>, Func<IMethodInterceptionBuilder, IMethodInterception>).

Remarks

This overload resolves the ambiguity between the IAdviser<T> and IQuery<TDeclaration> overloads for ITypeAmender, which implements both interfaces. The registration is made through the query.

Exceptions
Type Condition
ArgumentNullException

build is null.

ArgumentException

The delegate returned null, or a value that does not describe a complete interception.

InvalidOperationException

The delegate discarded a value that it created, or the project that executes the registration does not reference the Metalama.Extensions.Interceptors package.