OpCodes.Unbox 字段

定义

将值类型的已装箱的表示形式转换为其未装箱的形式。Converts the boxed representation of a value type to its unboxed form.

public: static initonly System::Reflection::Emit::OpCode Unbox;
public static readonly System.Reflection.Emit.OpCode Unbox;
 staticval mutable Unbox : System.Reflection.Emit.OpCode
Public Shared ReadOnly Unbox 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
79 < T >79 < T > 取消装箱 valTypeunbox valType 从 @no__t 的装箱表示形式中提取值类型数据。Extracts the value type data from obj, its boxed representation.

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

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

  2. 从堆栈中弹出对象引用,并取消装箱到值类型指针。The object reference is popped from the stack and unboxed to a value type pointer.

  3. 值类型指针被推送到堆栈上。The value type pointer is pushed onto the stack.

值类型在公共语言基础结构(CLI)中具有两种不同的表示形式:A value type has two separate representations within the Common Language Infrastructure (CLI):

  • 当值类型嵌入到另一个对象中时使用的 "原始" 窗体。A 'raw' form used when a value type is embedded within another object.

  • "装箱" 窗体,其中值类型中的数据被包装(装箱)到对象中,因此它可以作为独立实体存在。A 'boxed' form, where the data in the value type is wrapped (boxed) into an object so it can exist as an independent entity.

@No__t 0 指令将对象引用(类型 O)、值类型的装箱表示形式转换为值类型指针(托管指针,类型 &),其未装箱形式。The unbox instruction converts the object reference (type O), the boxed representation of a value type, to a value type pointer (a managed pointer, type &), its unboxed form. 提供的值类型(valType)是元数据标记,用于指示装箱对象中包含的值类型类型。The supplied value type (valType) is a metadata token indicating the type of value type contained within the boxed object.

Box (这是创建值类型的副本以在对象中使用所必需的),不需要 unbox 从对象复制值类型。Unlike Box, which is required to make a copy of a value type for use in the object, unbox is not required to copy the value type from the object. 通常,它只是计算装箱对象内已存在的值类型的地址。Typically it simply computes the address of the value type that is already present inside of the boxed object.

如果对象未装箱为 valType,则会引发 InvalidCastExceptionInvalidCastException is thrown if the object is not boxed as valType.

如果对象引用为空引用,则会引发 NullReferenceExceptionNullReferenceException is thrown if the object reference is a null reference.

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

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

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

适用于