OpCodes.Mkrefany 字段


将对特定类型实例的类型化引用推送到计算堆栈上。Pushes a typed reference to an instance of a specific type onto the evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Mkrefany;
public static readonly System.Reflection.Emit.OpCode Mkrefany;
 staticval mutable Mkrefany : System.Reflection.Emit.OpCode
Public Shared ReadOnly Mkrefany As OpCode 



下表列出了指令的十六进制和 Microsoft 中间语言(MSIL)程序集格式以及简短的参考摘要:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

格式Format 程序集格式Assembly Format 说明Description
C6 < T >C6 < T > mkrefany classmkrefany class 将类型 class 的类型化引用推送到堆栈上。Pushes a typed reference of type class onto the stack.

堆栈转换行为顺序如下:The stack transitional behavior, in sequential order, is:

  1. 指向片段的数据被推送到堆栈上。A pointer to piece of data is pushed onto the stack.

  2. 将弹出指针并将其转换为类型 class的类型化引用。The pointer is popped and converted to a typed reference of type class.

  3. 类型化的引用被推送到堆栈上。The typed reference is pushed onto the stack.

mkrefany 指令支持动态类型化引用的传递。The mkrefany instruction supports the passing of dynamically typed references. 指针的类型必须为 &*native int,并保存一段数据的有效地址。The pointer must be of type &, *, or native int, and hold the valid address of a piece of data. Class 是描述指针所引用的数据类型的类标记。Class is the class token describing the type of the data referenced by the pointer. Mkrefany 将类型化引用推送到堆栈上,同时提供指针和类型 class的不透明说明符。Mkrefany pushes a typed reference on the stack, providing an opaque descriptor of the pointer and the type class.

对类型化引用允许的唯一有效操作是将其传递到要求类型化引用作为参数的方法。The only valid operation permitted upon a typed reference is to pass it to a method that requires a typed reference as a parameter. 然后,调用方可以使用 RefanytypeRefanyval 指令分别检索类型(类)和地址。The callee can then use the Refanytype and Refanyval instructions to retrieve the type (class) and the address respectively.

如果找不到 class,则会引发 TypeLoadExceptionTypeLoadException is thrown if class cannot be found. 当 Microsoft 中间语言(MSIL)指令转换为本机代码而不是运行时,通常会检测到此情况。This is typically detected when Microsoft Intermediate Language (MSIL) instructions are converted to native code rather than at runtime.

以下 Emit 方法重载可以使用 mkrefany 操作码:The following Emit method overload can use the mkrefany opcode:

  • ILGenerator (OpCode,Type)ILGenerator.Emit(OpCode, Type)