Codes. Unbox Field
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:
||Extracts the value type data from
The stack transitional behavior, in sequential order, is:
An object reference is pushed onto the stack.
The object reference is popped from the stack and unboxed to a value type pointer.
The value type pointer is pushed onto the stack.
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.
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. The supplied value type (
valType) is a metadata token indicating the type of value type contained within the boxed object.
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.
InvalidCastException is thrown if the object is not boxed as
NullReferenceException is thrown if the object reference is a null reference.
TypeLoadException is thrown if the value type
valType cannot be found. This is typically detected when Microsoft Intermediate Language (MSIL) instructions are converted to native code, rather than at runtime.
The following Emit method overload can use the