Open sandboxFocus

Interface IInterceptorMethodBuilder

Lets the delegate given to Configure(Action<IInterceptorMethodBuilder>) shape the interceptor method that a template generates for a method call.

Namespace: Metalama.Extensions.Interceptors
Assembly: Metalama.Extensions.Interceptors.dll
Syntax
[CompileTime]
[InternalImplement]
public interface IInterceptorMethodBuilder
Remarks

The Method property is the builder of the generated method. It is created when it is first read, or after the delegates given to Configure(Action<IInterceptorMethodBuilder>) return. It then holds the signature that the engine derives from the intercepted method for the placement given by the methods of ITemplateInterception whose name starts with PlaceIn:

  • a receiver parameter, when the intercepted method has a receiver (see ReceiverMapping);
  • the parameters of the intercepted method, without default values and without params;
  • the parameters that the template adds, which are its run-time parameters whose names are properties of the arguments given by WithArgs(object).

The delegate can change the name, the accessibility, the names and the types of the parameters, and the attributes, and it can add parameters. The value of an added parameter is given by the SetArgument(IParameter, IExpression) method or by the property of the arguments that has its name, and it is passed at each call site. The reference kinds and the positions of the receiver and argument parameters and the return type cannot change, and the derived type parameters cannot be renamed and can only gain constraints: an attempt to do otherwise throws an InvalidOperationException. A type of a parameter can change to a type to which the argument converts implicitly, and meta.Proceed() casts it back. A parameter passed by reference keeps its type. The delegate can also add type parameters after the derived ones, and give their type arguments with the SetTypeArgument(ITypeParameter, IType) method.

The call sites whose generated methods have the same final signature, template, template arguments, tags, placement and granularity share one generated method. The values of the added parameters and the type arguments of the added type parameters are not part of this comparison.

The generated method is not visible in the code model to aspects, in any stage of the pipeline, and it is not in the code that the IDE generates. Method is a detached builder: its declaring type does not list it.

Properties

Name Description
Context

Gets the context of the call site for which the signature is built.

Method

Gets the builder of the generated interceptor method, pre-filled with the signature that the engine derives from the intercepted method.

ReceiverEligibility

Gets whether the receiver of the call can or must be mapped to the this of the generated method, at the current call site and at every call site of its group.

ReceiverMapping

Gets or sets how the receiver of the call is passed to the generated method. When it is Parameter, the first parameter of Method receives the receiver. When it is This, Method is an instance method without a receiver parameter.

Methods

Name Description
SetArgument(IParameter, IExpression)

Sets the value that the call site passes to a parameter that was added to the Method method builder, either by the template or by the delegate.

SetArgument(IParameter, TypedConstant)

Gives the value of a parameter added to the Method method at this call site, as a constant.

SetTypeArgument(ITypeParameter, IType)

Sets the type argument that the call site passes to a type parameter that the delegate added to the Method method builder.

Extension Methods