When you make calls to .NET assemblies or their methods or properties from PowerBuilder, you must follow PowerScript syntax rules. The following syntax rules are especially important for C# developers to keep in mind:
ls = create logger.LogServer
Note that a single dot (.) is used as a namespace separator in .NET conditional blocks.
#IF Defined PBDOTNET THEN
int i
for I = 1 to 10
System.Console.WriteLine(i)
next
#END IF
#IF Defined PBDOTNET THEN @System.Collections.ArrayList myList myList = create @System.Collections.ArrayList #END IF
The PowerBuilder preprocessor includes logic to distinguish the .NET System namespace from the PowerBuilder System keyword, therefore the use of the @ prefix is optional as a namespace identifier in the above example. However, you must include the @ identifier when you reference the .NET Type class in PowerScript code (@System.@Type or System.@Type). Also, if you use a PowerBuilder keyword for a .NET namespace name other than System, you must prefix the namespace name with the @ identifier.
Although PowerBuilder can support .NET Framework classes and namespaces, it does not support .NET keywords. For example, you cannot use the .NET keyword typeof, even if you prepend it with the @ identifier.
You must use PowerScript rules when your script extends beyond a single line. The line return character indicates the end of a line of script except when it is preceded by the ampersand (&) character. Semicolons are not used to indicate the end of a PowerScript line.
#IF Defined PBDOTNET THEN
int myArray[-2 to 5]
//in C#, you would have to initialize array
//with code like: int[] myArray = new int[7]
myArray[-1]=10 //assigning a value to 2nd array index
#END IF
In PowerBuilder, unbounded arrays can have one dimension only. The default start index for all PowerBuilder arrays is 1. The GetValue method on a C# array returns 0 for a default start index identifier, so you would call array_foo.GetValue (0) to return the first element of the array array_foo. However, after a C# array is assigned to a PowerBuilder array, you access the elements of the array with the PowerBuilder index identifier. In this example, you identify the first element in PowerScript as array_foo[1].
.NET is case sensitive, but PowerBuilder is not. The .NET Framework does provide a way to treat lowercase and uppercase letters as equivalent, and the PowerBuilder to .NET compiler takes advantage of this feature. However, if the .NET resources you are accessing have or contain names that differ only by the case of their constituent characters, PowerBuilder cannot correctly compile .NET code for these resources.
Code inside a .NET conditional compilation block is not visible to the main PowerBuilder compiler. If you use variables to hold data from the .NET environment that you want to access from outside the conditional block, you must declare the variables outside the conditional block. Variables you declare outside a .NET conditional block can remain in scope both inside and outside the conditional block.
You use a terminal exclamation mark (!) to access enumeration constants in PowerScript. For information about using enumeration constants in the .NET environment, see User-Defined Enumerations.