Επεξεργασία

Κοινή χρήση μέσω


RuntimeHelpers.PrepareMethod Method

Definition

Prepares a method for inclusion in a constrained execution region (CER).

Overloads

PrepareMethod(RuntimeMethodHandle)

Prepares a method for inclusion in a constrained execution region (CER).

PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[])

Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiation.

PrepareMethod(RuntimeMethodHandle)

Source:
RuntimeHelpers.CoreCLR.cs
Source:
RuntimeHelpers.CoreCLR.cs
Source:
RuntimeHelpers.CoreCLR.cs

Prepares a method for inclusion in a constrained execution region (CER).

public:
 static void PrepareMethod(RuntimeMethodHandle method);
public static void PrepareMethod (RuntimeMethodHandle method);
[System.Security.SecurityCritical]
public static void PrepareMethod (RuntimeMethodHandle method);
static member PrepareMethod : RuntimeMethodHandle -> unit
[<System.Security.SecurityCritical>]
static member PrepareMethod : RuntimeMethodHandle -> unit
Public Shared Sub PrepareMethod (method As RuntimeMethodHandle)

Parameters

method
RuntimeMethodHandle

A handle to the method to prepare.

Attributes

Remarks

Compilers use the PrepareMethod(RuntimeMethodHandle) method to handle virtual calls that are made inside a constrained execution region (CER). At JIT compilation time, the common language runtime does not usually have enough information about the target of a virtual call. Therefore, the runtime does not initially prepare that segment of the call graph. If the code that is using the CER has enough knowledge to determine the target at any point in time before the CER is actually entered, it can call PrepareMethod(RuntimeMethodHandle) to perform the same runtime preparation normally done for a CER rooted at the method specified as an argument.

Applies to

PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[])

Source:
RuntimeHelpers.CoreCLR.cs
Source:
RuntimeHelpers.CoreCLR.cs
Source:
RuntimeHelpers.CoreCLR.cs

Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiation.

public:
 static void PrepareMethod(RuntimeMethodHandle method, cli::array <RuntimeTypeHandle> ^ instantiation);
public static void PrepareMethod (RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation);
[System.Security.SecurityCritical]
public static void PrepareMethod (RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation);
public static void PrepareMethod (RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation);
static member PrepareMethod : RuntimeMethodHandle * RuntimeTypeHandle[] -> unit
[<System.Security.SecurityCritical>]
static member PrepareMethod : RuntimeMethodHandle * RuntimeTypeHandle[] -> unit
Public Shared Sub PrepareMethod (method As RuntimeMethodHandle, instantiation As RuntimeTypeHandle())

Parameters

method
RuntimeMethodHandle

A handle to the method to prepare.

instantiation
RuntimeTypeHandle[]

The instantiation to pass to the method.

Attributes

Remarks

You can provide generics support for compilers by using the PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) method. The common language runtime cannot prepare constrained execution regions (CERs) rooted in a method that has generic type parameters (either a type parameter on the class containing the method or one on the method itself) when those type parameters are instantiated as reference types.

You can use this overload to pass a specific instantiation (such as an array of types), specifying class type parameters first (if any), followed by method type parameters (if any). The runtime prepares that instantiation of the method. (This is necessary only if the instantiations you use contain at least one reference type parameter.) Thus, you can use a CER-style try clause in a generic method (or a nongeneric method on a generic class) and it will work reliably with instantiations of Int32 or other value types. To instantiate reference types such as String, you must use an explicit PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) method on the CER root method first.

Applies to