Skip to content

Latest commit

 

History

History
25 lines (13 loc) · 2.57 KB

ii.14.6.1-delegate-signature-compatibility.md

File metadata and controls

25 lines (13 loc) · 2.57 KB

II.14.6.1 Delegate signature compatibility

This clause defines the relation delegate-assignable-to, which is a variant of method-signature-compatible-withI.8.7.1) and covers delegate construction.

Delegates are bound to target methods through the newobj IL instruction (§III.4.21) passing a method pointer for the target method and an object reference, if the target is an instance method, or null, if the target is a static method. The target method is loaded onto the evaluation stack through the ldftn, ldvirtftn, or one of the load IL instructions, at which time the signature of the method is available.

The signature of a delegate is the signature of the Invoke method on the delegate type. [Note: the signature does not include the type of the this pointer, if any, bound at delegate creation time. end note]

Delegates can only be verifiably bound to target methods where:

  1. the signatures of the target method is delegate-assignable-to the signature of the delegate;

  2. The object reference's verification type is verifier-assignable-toIII.1.8.1.2.3) the this signature of the target method, if the target is an instance method, or null, if the target method is a static method. The special verification rules for delegate construction are captured by the newobjIII.4.21) instruction.

The delegate-assignable-to relation is defined in terms of the parameter types, ignoring the this parameter, if any, the return type and calling convention. (Custom modifiers are not considered significant and do not impact compatibility.)

A target method or delegate of type T is delegate-assignable-to a delegate of type D if and only if all of the following apply:

  1. The calling conventions of T and D shall match exactly, ignoring the distinction between static and instance methods (i.e., the this parameter, if any, is not treated specially). [Note: delegate-assignable-to does not consider the type of this, if any, that is covered by the additional verification rules above. end note]

  2. T and D have the same number of parameters, ignoring any this parameter if T is a method.

  3. For each parameter type U of T, ignoring any this parameter if T is a method, and corresponding type V of D, U is assignable-toI.8.7.3) V.

  4. The return type U of T and return type V of D, V is assignable-to U.