Automatic boxing
- Last Updated: January 26, 2026
- 5 minute read
- OpenEdge
- Version 12.8
- Documentation
ABL automatically performs the required boxing or unboxing operation in the following situations:
- When you assign a value between an ABL primitive and a .NET property,
data member, or method return value defined as an appropriate
System.Object, the appropriate boxing (to theSystem.Object) or unboxing (from theSystem.Object) occurs.Note: Assigning aSystem.Objectto a .NET primitive (or equivalent object) type is invalid because of type narrowing, but ABL makes an exception when assigning aSystem.Objectto an ABL primitive by automatically converting the types. - When you assign a compatible ABL array type to a .NET property
or data member defined as a
System.Object.Note: ABL does not automatically convert types when assigning aSystem.Objectto an ABL array. - For a .NET method or constructor, when you pass an ABL
primitive or compatible array type to an
INPUTparameter defined as aSystem.Object.Note: ABL does not automatically convert types when passing these ABL types to anOUTPUT System.Objectparameter. - When you assign between a compatible ABL array type and a .NET array object type, or when you pass a compatible ABL array type to a .NET method or constructor parameter defined as a .NET array object type.
For example, when you assign an ABL INTEGER
to a .NET data element defined as a System.Object, ABL
automatically boxes the INTEGER into to the System.Object as the default matching System.Int32. However, if the .NET property or data member
requires a conversion to a .NET mapped data type other than the default match, you must
use the ABL BOX function (see BOX function in the ABL
Reference). The same is true of assigning an ABL INTEGER array to a System.Object: ABL
automatically boxes and stores the ABL array as a one-dimensional .NET array of System.Int32 elements ("System.Int32[]"), and you can also manually box the ABL array as a .NET
array of a non-default matching element type, such as an "System.Byte[]", using the BOX function.
For an ABL array of any other (non-mapped) .NET object type, such as of System.Drawing.Point or Progress.Windows.Form elements, ABL boxes the ABL array to a System.Object as the specified one-dimensional .NET array,
for example "System.Drawing.Point[]" or "Progress.Windows.Form[]".
Similarly, if you assign a System.Object to
an ABL INTEGER data element, ABL automatically
unboxes the System.Object and the result depends
on the content of the System.Object (see Get .NET data member, property, and method return values).
If the System.Object is a .NET mapped data
type, ABL unboxes the .NET mapped data type from the System.Object and
attempts to assign the default matching ABL primitive type that
results to the ABL INTEGER data element. If the
ABL primitive type unboxed from the System.Object is
compatible, in this case, with INTEGER, the assignment
works. Otherwise, the AVM raises a run-time error.
If you assign a compatible ABL array, such as an INTEGER EXTENT or
a System.Drawing.Point EXTENT,
to a System.Object, ABL boxes the ABL array, in
this case, as the default matching .NET array object, "System.Int32[]",
or the equivalent one-dimensional .NET array object, "System.Drawing.Point[]",
respectively. However, you cannot assign a similarly boxed System.Object to
the equivalent ABL array, without manually unboxing the System.Object using
the UNBOX function (see Manual boxing). If you want to assign
an ABL primitive array and box it as a .NET array of elements
other than the default match, you must assign the result of executing
the BOX function for the ABL array,
indicating the AS data type to the function that
matches the target element type (see Manual boxing).
When passing a ABL primitive or compatible array type to a .NET method or
constructor INPUT parameter defined as System.Object,
ABL automatically boxes the ABL primitive or array type into the System.Object parameter
(on INPUT) or unboxes the System.Object parameter
as the default matching .NET type or the equivalent .NET array
object type, respectively. In addition for an ABL primitive, if
the System.Object parameter requires a .NET mapped
data type other than the default match, you can specify the AS data
type option on the ABL primitive argument in order to box the value
to a specified .NET mapped type. However, for an ABL primitive
array argument, if you want to box it as a .NET array of elements
other than the default match, you must execute the BOX function on
the parameter for the ABL array argument, indicating the AS data
type to the function that matches the target element type.
For example, if you pass an ABL INTEGER to a System.Object
INPUT parameter of a .NET method, by default, ABL
boxes the INTEGER value as a System.Int32.
If you specify the AS UNSIGNED-BYTE option when
passing the INTEGER value, ABL boxes the value
as a System.Byte. For more information on using
the AS data type option, see Specify .NET constructor and method parameters and the Pass ABL data types to .NET constructor and method parameters. If you pass
an ABL INTEGER array to a System.Object
INPUT parameter of a .NET method, ABL boxes the ABL
array as a "System.Int32[]". However, if you want
to box the ABL INTEGER array as another compatible .NET array
of mapped type elements (such as a "System.Byte[]"),
you must execute the BOX function on the parameter
for the INTEGER array, indicating the AS data
type to the function. If you pass any other compatible ABL array
(such as System.Drawing.Point EXTENT), ABL boxes
it the equivalent one-dimensional .NET array (such as "System.Drawing.Point[]").
When you assign, or pass .NET method parameters, between compatible ABL arrays and .NET arrays, ABL is also doing an automatic boxing (from ABL non-object to .NET object type) or unboxing (from .NET object to ABL non-object type) operation. In this case, the operation follows array mapping rules that determine how an ABL array is converted to a .NET array object type (boxing) and how a .NET array object is converted to an ABL array type (unboxing). For more information on the rules for mapping between ABL and .NET arrays, see Access and use .NET arrays.
Note that for ABL routines of any kind (class-based methods, constructors, user-defined functions, or procedures), ABL does no automatic boxing or unboxing between ABL non-object types and .NET object types involved in parameter passing. Instead, you must either use the ABL BOX or UNBOX function (as appropriate) or assign arguments to box or unbox them appropriately before or after calling the ABL routines, as described in the following section.