C# language vs. PowerScript language

Data types

The following table lists the data type mappings between PowerBuilder and .NET. Keep in mind that PowerBuilder and .NET data types may not have the same definitions even if the type name is the same or similar. For PowerBuilder data types, refer to the section called “Datatypes” in PowerScript Reference. For .NET data types, refer to the Types and variables web page.

PowerBuilder char maps to .NET string, and PowerBuilder ref char maps to .NET char.

PowerBuilder blob[] maps to .NET byte[][]. PowerBuilder blob two-dimensional array is unsupported.

The index in PowerScript starts from 1, while the index in .NET starts from 0, therefore, PowerBuilder Array[1] maps to .NET Array[0].

When the .NET function is imported to the NVO, the two-dimensional array will be converted to Any data type when passed as arguments or return values, and the first-dimensional array will be converted to Any data type when passed as return values, because PowerBuilder does not support using the array argument as the return value of a function (the developer can use the corresponding array or any to receive the value).

For numeric data type, the mapping between PowerBuilder and .NET can be fuzzy. For example, even the .NET integer-type should be mapped to PowerBuilder long-type normally, the .NET function "public int Add(int parm1, int parm2)" can also be called by the integer-type parameter in PowerBuilder (instead of the long-type parameter).

For standard data type and array data type, PowerBuilder can map to the .NET nullable and non-nullable types, for example, PowerBuilder integer type can map to the .NET short and short? types.

For numeric array, PowerBuilder and .NET must be exactly mapped. For example, PowerBuilder integer-type array can only map to the .NET short-type array.

Date and Time can only be used in arguments and cannot be used in return values; when used in arguments, they are passed to .NET as DateTime; when passed by Ref, the value will be sync to the Date and Time variables; they cannot be used as return values to receive DateTime return values from .NET; and cannot set or receive DateTime property values from .NET.

When passing a PowerBuilder variable-length array to .NET, .NET can use list to process the data from the PowerBuilder variable-length array, and then assign the data to the PowerBuilder ref variable-length array or return the data directly. At the end of this section, there is a sample of PowerScript code that uses the variable-length array to receive the double-type data from .NET.

PowerBuilder

C#

Array (one and two dimension)

Reference

Generic Nullable<T>

int

short

Supported

Supported

Supported

uint

ushort

Supported

Supported

Supported

long

int

Supported

Supported

Supported

longptr

int32/int64

Supported

Supported

Supported

ulong

uint

Supported

Supported

Supported

longlong

long/Int64

Supported

Supported

Supported

boolean

bool

Supported

Supported

Supported

char

string/char

Supported

Supported

Supported

string

string

Supported

Supported

Unsupported

real

float

Supported

Supported

Supported

double

double

Supported

Supported

Supported

decimal

decimal

Supported

Supported

Supported

blob

byte[]

Supported

Supported

Supported

Date

DateTime

Supported

Supported

Supported

DateTime

DateTime

Supported

Supported

Supported

Time

DateTime

Supported

Supported

Supported


Supported return value data types

The following table lists the return value data type mappings between PowerBuilder and .NET.

PowerBuilder

C#

int

short

uint

ushort

long

int

longptr

int32/int64

ulong

uint

longlong

long/Int64

boolean

bool

char

char

string

string

real

float

double

double

decimal

decimal

blob

byte[]

DateTime

DateTime


Classes

.NET classes are supported, except for the following:

  • Interface

  • Struct

  • Abstract, Generic, Internal, Partial, Protected, Private, or Static class

Nested class is supported, except that using the plus sign (“+”) instead of the dot (“.”) to access the nested class: [namespace].[class]+[nested-class].

Functions

.NET functions are supported, except for the following:

  • Private, Protected, Extension, or Generic function

Function parameters and return values are supported with the following exceptions:

  • Using array of generic type, delegate, interface, or class (including abstract class) as the parameters or return value of a function

  • Passing parameters by reference is supported when the developer adds the keyword "ref" or "out" explicitly; however, passing parameters by reference to a constructor function is unsupported

  • The params keyword

  • The optional attribute of arguments

  • Object-type or Sbyte-type arguments

  • Transaction object array

  • Date and Time can only be used in arguments and cannot be used in return values.

  • The C# enumerated datatype is supported through the PB Long datatype.

  • Using Struct or generic type as the parameter or in the callback function

The return object will be auto-instantiated as a DotNetObject object; users do not need to create it, but can destroy it when it is no longer used.

The return object cannot be used directly as a parameter by reference; users will need to receive the return object first, and then use it as a parameter. For example,

This statement is unsupported:

ls_ret = lnv_TestCLR1.TestReferenceObj (ref lnv_TestCLR1.TestReturnObj())

This statement is supported:

//lnv_ReturnObj is auto-instantiated
lnv_ReturnObj = lnv_TestCLR1.TestReturnObj()
ls_ret = lnv_TestCLR1.TestReferenceObj (ref lnv_ReturnObj)

The generic type, delegate, interface, or class (including abstract class) will be converted to DotNetObject when used as the parameter.

The generic type, delegate, interface, or class (including abstract class) can be passed by reference when used as the parameter.

Properties

Each property will have two functions imported (one for getting the property value and the other for setting). Read-only or write-only property will have only one function imported.

Getting or setting a property is supported, except for the following:

  • More than one-level dot notation for getting or setting a property. For example, the following is unsupported: Student.Informations.Name="Kit".

  • Using array of generic type, delegate, interface, or class (including abstract class) as the value of a property.

  • Private or Protected property

  • Indexer

  • Sbyte-type property

  • Transaction object array

  • Struct

  • The C# enumerated datatype is supported through the PB Long datatype.

Fields

Data fields are unsupported.

Transaction Objects

Transaction Objects (specifically IAdoConnectionProxy) are only supported in .NET Framework, but not in .NET and .NET Core.

Transaction Objects from .NET do not support Oracle Data Provider for .NET (Oracle.DataAccess.Client or Oracle.ManagedDataAccess.Client).