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).

C#
public static void PrepareMethod(RuntimeMethodHandle method);
C#
[System.Security.SecurityCritical]
public static void PrepareMethod(RuntimeMethodHandle method);

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

.NET 10 ja muud versioonid
Toode Versioonid
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation);
C#
[System.Security.SecurityCritical]
public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation);
C#
public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation);

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

.NET 10 ja muud versioonid
Toode Versioonid
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1