.NET Automatic Type Conversion (Magic xpa 4.x)
Magic xpa automatically converts Magic xpa types to .NET types and vice versa; so, for example, it is possible to send Magic xpa variables to .NET methods without performing cast on them.
The conversion rules are as follows:
|
|
Numeric
|
SByte, Byte , Int16, Uint16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Decimal, Single, Double, Float
|
Alpha, Unicode
|
Char, Char[], String, StringBuilder
|
Date
|
DateTime
|
Time
|
DateTime, TimeSpan
|
Logical
|
Boolean
|
BLOB
|
Byte, Byte[], Char, Char[], String, StringBuilder
|
Vector
|
ICollection (only from .NET to Magic xpa), IList and objects that implement Indexers through the usage of 'this' keyword. Only indexers that have integer indexes can be converted.
|
|
-
There is no automatic conversion for nested vectors.
-
NET arrays are not automatically converted to a Magic type.
-
Usually you can use simple values (such as strings or numbers) and Magic xpa will automatically convert them to the proper .NET variable type. But, when the conversion is not unique (for example, the method is overloaded and can receive both Int and Long variables) or that you need to specifically convert the value to a .NET type, you will have to use the DNCast() function to specifically do the conversion.
-
When trying to update a .NET Datetime property with a number, such as Datetime+12, the automatic conversion will fail and you will receive a syntax error. This is because the Magic xpa internal representation of a date is numeric, so the end result is numeric. To solve this issue you can use the Magic xpa AddDate function.
|
Automatic conversion is used when: