Try OpenEdge Now
skip to main content
GUI for .NET Programming
Using .NET data types in ABL : Passing ABL data types to .NET constructor and method parameters : Indicating explicit .NET data types
 

Indicating explicit .NET data types

In Table 10, note that some ABL primitive types map to two or more alternative .NET data types, and one of these alternative mappings represents a default match for the given ABL primitive type (see Default matching ABL and .NET data types).
Two cases exist where the default matching data type is insufficient and you must identify the explicit .NET data type you are passing to a parameter in order for ABL to call the method as you expect:
*For .NET constructors or methods whose signatures are overloaded by alternative .NET types or arrays of mapped type elements that map to the same ABL primitive or primitive array type, you need to explicitly identify the .NET mapped data type or mapped type array element to ABL so it can invoke the correct constructor or method overloading. For more information on constructor and method overloading in ABL, see OpenEdge Development: Object-oriented Programming.
*For a System.Object INPUT parameter of a .NET constructor or method, ABL automatically boxes the passed ABL primitive or primitive array type into its default matching .NET mapped type or array of mapped type elements. However, if you need the target type to be something other than the default match, you must explicitly indicate the .NET mapped data type to use for the INPUT ABL primitive or primitive array elements. A common example of this is the SetValue( ) method on System.Array.
For ABL primitive arguments, ABL provides an AS option on passed .NET constructor and method parameters to indicate an explicit .NET data type for each ABL primitive type that has alternative .NET data type mappings. You indicate the explicit .NET data type by specifying a corresponding AS data type keyword for the AS option (see Table 11). For more information on the syntax of the AS option for passing .NET mapped data type parameters, see Specifying .NET constructor and method parameters. Note that if the .NET data type you want to pass is the default match for the ABL primitive type you are passing, you simply pass the ABL value without the AS option.
For ABL primitive arrays, ABL provides a BOX function that you can invoke on an appropriate INPUT parameter of a .NET constructor or method for the ABL primitive array argument, and in this BOX function invocation, you can indicate the target .NET array of mapped types by specifying the corresponding AS data type keyword (see Table 11) as a character expression. For more information on using the BOX function, see .NET boxing support. For OUTPUT parameters, you must pass an argument defined as the indicated .NET array of mapped types and assign the .NET array output parameter result to a matching ABL primitive array. However, for performance reasons, you might want to work with the output .NET array directly instead of converting it to an ABL array. For more information on assigning between ABL and .NET arrays, see Accessing and using .NET arrays.
Note, again, that if there is no overloading of a parameter, you do not have to specify an AS option, and the ABL data type of the argument will match any of the .NET data types supported by the implicit mappings. If you do not specify the AS option for an overloaded parameter, and none of the available overloadings represents the default match for the ABL primitive type you pass, ABL raises a compile-time ambiguity error.
The following example shows three different overloadings of the static Max( ) method called on the System.Math class from ABL. The first overloading maps the parameters to the INTEGER default match, System.Int32. The remaining overloadings map the parameters to the .NET data type specified by the given AS data type:
DEFINE VARIABLE iResult AS INTEGER NO-UNDO.

ASSIGN
  iResult = System.Math:Max(-2147483647, 2147483647)
  iResult = System.Math:Max(65535 AS UNSIGNED-SHORT, 65 AS UNSIGNED-SHORT)
  iResult = System.Math:Max(127 AS BYTE, 12 AS BYTE).