OpCodes.Unbox_Any 字段

定义

将指令中指定类型的已装箱的表示形式转换成未装箱形式。Converts the boxed representation of a type specified in the instruction to its unboxed form.

public: static initonly System::Reflection::Emit::OpCode Unbox_Any;
public static readonly System.Reflection.Emit.OpCode Unbox_Any;
 staticval mutable Unbox_Any : System.Reflection.Emit.OpCode
Public Shared ReadOnly Unbox_Any 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
A5 < T >A5 < T > 取消装箱。任意 typeTokunbox.any typeTok 从 @no__t 的装箱表示形式中提取数据。Extract the data from obj, its boxed representation.

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

  1. obj 的对象引用推送到堆栈上。An object reference obj is pushed onto the stack.

  2. 从堆栈中弹出对象引用,并取消装箱到指令中指定的类型。The object reference is popped from the stack and unboxed to the type specified in the instruction.

  3. 生成的对象引用或值类型被推送到堆栈上。The resulting object reference or value type is pushed onto the stack.

当应用于值类型的装箱形式时,unbox.any 指令提取 @no__t 中包含的值(类型为 O),因此等效于 unbox 后跟 ldobjWhen applied to the boxed form of a value type, the unbox.any instruction extracts the value contained within obj (of type O), and is therefore equivalent to unbox followed by ldobj.

当应用于引用类型时,@no__t 的指令与 @no__t typeTok 的效果相同。When applied to a reference type, the unbox.any instruction has the same effect as castclass typeTok.

如果操作数 typeTok 是泛型类型参数,则运行时行为取决于为该泛型类型参数指定的类型。If the operand typeTok is a generic type parameter, then the runtime behavior is determined by the type that is specified for that generic type parameter.

如果 obj 不是装箱类型,则会引发 InvalidCastExceptionInvalidCastException is thrown if obj is not a boxed type.

如果 obj 为 null 引用,则会引发 NullReferenceExceptionNullReferenceException is thrown if obj is a null reference.

以下 @no__t 0 方法重载可以使用 @no__t 操作码:The following Emit method overload can use the unbox.any opcode:

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

适用于