RuntimeHelpers.PrepareMethod Method (RuntimeMethodHandle, RuntimeTypeHandle[])
Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiation.
Assembly: mscorlib (in mscorlib.dll)
[<SecurityCriticalAttribute>] static member PrepareMethod : method:RuntimeMethodHandle * instantiation:RuntimeTypeHandle[] -> unit
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.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Available since 2.0