Try OpenEdge Now
skip to main content
.NET Open Clients
Passing Parameters : ABL data type mappings : Unknown value (?) as a parameter : Using .NET nullable value types
 
Using .NET nullable value types
In ProxyGen, if you specify that a supported value type parameter or return value can have the Unknown value (?), and you have chosen the option to use nullable value types, the method is defined with the corresponding nullable type; otherwise the parameter is defined using the .NET value type.
The following is an example of a C# proxy method signature that does not support Unknown value (?) for the first and third parameters:
foo(int i, string s, bool b)
The following is an example of a C# proxy method that allows all the parameter values to have Unknown value (?), using nullable value types where necessary:
foo(System.Int32? i, string s, System.Boolean? b)
.NET nullable types are represented using the following syntax:

Syntax

ValueType?
Where ValueType is a built-in .NET value type that has a corresponding nullable type, and ? identifies the value type as nullable.
A nullable type is actually a generic structure type and the ValueType? syntax is shorthand for the generic structure System.Nullable<ValueType>. These forms are interchangeable. However, the .NET Open Client uses the ValueType? form to represent nullable types in a proxy.
The following table shows the mapping between ABL primitive types and the corresponding .NET nullable value types.
Table 4. ABL primitive type to .NET nullable value type mappings
This ABL primitive type...
Maps to this .NET nullable type...
DATE
DATETIME
DATETIME-TZ
System.Datetime?
DECIMAL
System.Decimal?
INT64
System.Int64?
INTEGER
System.Int32?
LOGICAL
System.Boolean?
RECID
System.Int64?
To set the value of an object with a nullable value type (nullable type object), you can directly assign it a value as if you were setting an object with the corresponding value type, and you can also assign it directly to null. When reading the value of a nullable type object, you need to know if the object is null (has no value) in order to avoid throwing an exception when reading its value, which is undefined when set to null. Also, to read the value of a nullable type object, you must access a property of the object that contains the value. Therefore, the System.Nullable<ValueType> generic structure supports the following read-only properties for nullable type objects:
*HasValue — A property of type System.Boolean that is true if the object has a value and is false otherwise (the object is set to null)
*Value — A property of type ValueType that returns the object's value if HasValue is true, and throws a System.InvalidOperationException exception if HasValue is false
You can also directly test a nullable type object for null using the == and != operators, and directly access the value of a non-null nullable type object.
For example, within a C# method, you can use nullable type objects as follows:
System.Int32? intNullable; // Nullable value type object
System.Int32  intValue;    // Corresponding value type object

intNullable = 10;                // Set a nullable object to a value
intValue = intNullable.Value;    // Get the value of the nullable object
intNullable = null;              // Set the nullable object to null
. . .

if (intNullable.HasValue)  // Test if nullable object is null before reading
  intValue = intNullable.Value;  // The object has a value; read its property
else
  intValue = 0;                  // The object is set to null; assigning 0

. . .

if (intNullable != null)  // Directly test if nullable object is null
  intValue = intNullable;        // The object has a value; read directly
else
  intValue = 0;                  // The object is set to null; assigning 0
For more information on the characteristics of nullable value types, including additional methods and C# operators that they support, see the Microsoft .NET documentation on using nullable types in C#.