RuntimeHelpers.PrepareMethod 方法
定义
准备一个要包含在受约束的执行区域 (CER) 中的方法。Prepares a method for inclusion in a constrained execution region (CER).
重载
| PrepareMethod(RuntimeMethodHandle) |
准备一个要包含在受约束的执行区域 (CER) 中的方法。Prepares a method for inclusion in a constrained execution region (CER). |
| PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) |
准备一个要包含在受约束的执行区域 (CER) 中的具有指定实例化的方法。Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiation. |
PrepareMethod(RuntimeMethodHandle)
准备一个要包含在受约束的执行区域 (CER) 中的方法。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)
参数
- method
- RuntimeMethodHandle
要准备的方法的句柄。A handle to the method to prepare.
- 属性
注解
编译器使用 PrepareMethod(RuntimeMethodHandle) 方法来处理 (CER) 在受约束的执行区域内进行的虚拟调用。Compilers use the PrepareMethod(RuntimeMethodHandle) method to handle virtual calls that are made inside a constrained execution region (CER). 在 JIT 编译时,公共语言运行时通常不具有关于虚拟调用目标的足够信息。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. 如果使用 CER 的代码有足够的知识来确定在实际输入 CER 之前的任何时间点,则它可以调用 PrepareMethod(RuntimeMethodHandle) 来执行通常为在指定为参数的方法中的 CER 执行相同的运行时准备工作。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.
适用于
PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[])
准备一个要包含在受约束的执行区域 (CER) 中的具有指定实例化的方法。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())
参数
- method
- RuntimeMethodHandle
要准备的方法的句柄。A handle to the method to prepare.
- instantiation
- RuntimeTypeHandle[]
要传递给该方法的实例化。The instantiation to pass to the method.
- 属性
注解
您可以使用方法为编译器提供泛型支持 PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) 。You can provide generics support for compilers by using the PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) method. 公共语言运行时无法 (Cer) 提供泛型类型参数的方法中的受约束的执行区域, (在包含方法的类上的类型参数,或在将这些类型参数实例化为引用类型时) 方法本身。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. 仅当你使用的实例化至少包含一个引用类型参数时,才需要执行此操作。 ) 因此,你可以使用 try 泛型方法中的 CER 样式子句 (或泛型类中的非泛型方法) ,并且它可与 Int32 或其他值类型的实例化一起使用。 ((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. 若要实例化引用类型(如 String ),则必须 PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) 先对 CER 根方法使用显式方法。To instantiate reference types such as String, you must use an explicit PrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[]) method on the CER root method first.