RuntimeHelpers.PrepareMethod Method (RuntimeMethodHandle, RuntimeTypeHandle[])

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.Runtime.CompilerServices
Assembly:  mscorlib (in mscorlib.dll)

[SecurityCriticalAttribute]
public static void PrepareMethod(
	RuntimeMethodHandle method,
	RuntimeTypeHandle[] instantiation
)

Parameters

method
Type: System.RuntimeMethodHandle

A handle to the method to prepare.

instantiation
Type: System.RuntimeTypeHandle[]

The instantiation to pass to the method.

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.

SecurityCriticalAttribute

requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

.NET Framework
Available since 2.0
Return to top
Show: