NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Boxing and Unboxing of Values

For every Value Type, the VOS defines a corresponding Reference Type called the boxed type. The reverse is not true: Reference Types do not in general have a corresponding Value Type. The representation of a value of a boxed type (a boxed value) is a location where a value of the Value Type can be stored. A boxed type is an object type and a boxed value is an object.

All Value Types have an operation called box. Boxing a value of any Value Type produces its boxed value, i.e. a value of the corresponding boxed type containing a bit copy of the original value. All boxed types have an operation called unbox. Unboxing is the opposite operation to boxing: it copies the bit sequence from the boxed value to create a value of the underlying Value Type.

Notice that interfaces and inheritance are defined only on Reference types. Thus, while a Value Type definition (see Value Type Definition) can specify both interfaces that must be implemented by the Value Type and a class from which it inherits, these apply only to boxed values.

Note: In PDC, the implementation of boxed value types is incomplete. While any value type can be boxed, the result should be considered to have type System.Object, System.ValueType, or System.Enum rather than a specific type that refers only to the particular boxed type.

CLS Rule 1: Boxed value types are not part of the CLS. Instead, use System.Object, System.ValueType or System.Enum, as appropriate.

CLS (consumers): need not import boxed value types.

CLS (extenders): need not provide syntax for defining or using boxed value types.

CLS (frameworks): must not use boxed value types in their publicly exposed aspects.