To use enumerations that you import from a .NET assembly, you must surround the enumeration references in a conditional compilation block that is valid for your .NET target environment. You must also append an exclamation mark (“!”) to each of the enumeration’s constant strings that you declare in the conditional code block.
For example, the following code defines the .NET enumeration class TimeOfDay:
Public enum TimeOfDay
{
Morning = 0,
AfterNoon,
Evening
}
In PowerScript, you reference a .NET enumeration constant string as follows, when TimeOfDay is an enumeration class in the ns_1.ns_2 namespace:
#if defined PBDOTNET THEN
ns_1.ns_2.TimeOfDay a
a=ns_1.ns_2.TimeOfDay.Morning!
#end if
When you set a system-defined enumeration constant in standard PowerBuilder applications, there is no issue regarding the scope of the constant definition, since all system enumeration constants are uniquely defined. However, for .NET enumerations, you must define a scope for the constant using the syntax:
enumerationType.enumerationEntryName!
If the enumeration class is declared under a namespace, you must include the namespace when you set an enumeration constant:
namespacename.enumerationType.enumerationEntryName!
If there is no enumerationType enumeration class prefacing the declaration of a constant in a .NET conditional code block, PowerBuilder assumes the enumeration is a system-defined type and returns an error if the system-defined type is not found.
The syntax for a PowerBuilder system enumeration constant in the .NET environment is:
[enumerationType.]enumerationEntryName!
Although you cannot use dot notation in a constant declaration for a system-defined enumeration in standard PowerScript, the pb2cs compiler must let you use dot notation for constant declarations that you make in a conditional compilation block for the .NET environment. Prefixing a constant declaration in the .NET environment with a PowerBuilder system enumeration name is equivalent to making the same declaration without a prefix.
The VM initially checks whether the enumerationType is a declared .NET enumeration class. If it does not find the enumeration class, it checks whether the enumerationType is a PowerBuilder system enumeration. When the enumerationType matches the name of a PowerBuilder system enumeration, the VM sets the constant for your .NET application or component.
Therefore, for the system Alignment enumeration, the constant
declaration Alignment.Left!
produces
the same result as the Left!
declaration
inside a .NET conditional code block. Outside such a code block,
the Alignment.Left!
declaration
causes a compiler error.