Every value has an associated type, which defines attributes such as the amount of space allocated to the value, the range of possible values it can have, and the members that it makes available. Many values can be expressed as more than one type. For example, the value 4 can be expressed as an integer or a floating-point value. Type conversion creates a value in a new type that is equivalent to the value of an old type, but does not necessarily preserve the identity (or exact value) of the original object.
To perform conversion from derived class to a base class, base class back to the original derived class or Conversion from a type that implements an interface to an interface object that represents that interface, use the wrap method. You can use the conversion types defined in CNClrLib.Host.Helper to perform conversions between inbuilt data types, as well as use TClrConvert class to convert a base data type to another base data type and TClrBitConverter class to Converts base data types to an array of bytes, and an array of bytes to base data types. All the base type conversion types are declared in CNClrLib.Host.Helper namespace.
Conversion between inbuilt Data Types
Widening conversions involve the creation of a new value from the value of an existing type that has either a more restrictive range or a more restricted member list than the target type. Widening conversions cannot result in data loss (although they may result in a loss of precision). Because data cannot be lost.
For example, the _Decimal interface type supports conversions from Byte, Char, Int16, Int32, Int64, SByte, UInt16, UInt32, and UInt64 values using the TClrConvert class defined in the CNClrLib.Host.Helper namespace. The following example illustrates some of these conversions in assigning values to a _Decimal variable.
Narrowing conversions involve the creation of a new value from the value of an existing type that has either a greater range or a larger member list than the target type. Because a narrowing conversion can result in a loss of data, it is often require that the conversion be made explicit through a call to a conversion method called wrap method or use the AsXXXX method of the interface object. Example _Decimal.AsIConvertible, the interface _Decimal provides an AsXXXX methods (such as AsIConvertible) which represent all the base classes as well as inherited interfaces defined in the .net framework. Doing so means you don't need to do explicit wrapping conversion, just call the AsXXXX method of the interface and the interface object will be converted to the specific AsXXXX method's return data type. To get the original .net object from the wrap DFL object use the Unwrap method.
Custom Conversions with the ChangeType Method