User-Defined Enumerations
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.
Declaring .NET enumerations in PowerScript
You must also
append an exclamation mark (�!�) to each of
the enumeration�s constant strings that you declare in
the conditional code block.
class TimeOfDay:
|
1 |
Public enum TimeOfDay |
|
1 |
{ |
|
1 |
Morning = 0, |
|
1 |
AfterNoon, |
|
1 |
Evening |
|
1 |
} |
string as follows, when TimeOfDay is an enumeration class in the
ns_1.ns_2 namespace:
|
1 |
#if defined PBDOTNET THEN |
|
1 |
ns_1.ns_2.TimeOfDay a |
|
1 |
a=ns_1.ns_2.TimeOfDay.Morning! |
|
1 |
#end if |
Scope of enumeration constant
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:
|
1 |
<var>enumerationType</var>.<var>enumerationEntryName</var>! |
must include the namespace when you set an enumeration constant:
|
1 |
<var>namespacename</var>.<var>enumerationType</var>.<var>enumerationEntryName</var>! |
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.
in the .NET environment is:
|
1 |
[<var>enumerationType</var>.]<var>enumerationEntryName</var>! |
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.