Open sandboxFocus

Property ReceiverMapping

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.

Declaration
InterceptorReceiverMapping ReceiverMapping { get; set; }
Property Value
Type Description
InterceptorReceiverMapping
Remarks

The generated method is static by default: the value is Parameter when the intercepted method has a receiver, and None when it is static. The only exception is a protected method of a base type of the calling type, which a static method cannot call through a receiver parameter. IsThisRequired is then true, the value is This, and it cannot change.

A delegate can change the value from Parameter to This, and back, when IsThisEligible is true and IsThisRequired is false (see ReceiverEligibility). It must do so before it reads Method, because the mapping determines the signature of the method builder. The IsStatic property of Method then follows the mapping and cannot be changed: the method is an instance method if and only if the mapping is This.

Exceptions
Type Condition
InvalidOperationException

The value is set after Method was read, it is set to This when IsThisEligible is false, it is set to Parameter when IsThisRequired is true, or it is set to None.