At Intertech we're trying to use the .NET DLL importer, wehave a structure defined in PowerBuilder called columninfo which has four elements: a_name (string), s_dbname(string), l_columnidsource (long), and l_columnidtarget (long). So the structure has two strings and two longs.
We then created a C# class with the following code:
namespace S_Interface.Models
{
public class s_columninfo
{
public string s_name { get; set; }
public string s_dbname { get; set; }
public int? l_columnidsource { get; set; }
public int? l_columnidtarget { get; set; }
public s_columninfo()
{
s_name = string.Empty;
s_dbname = string.Empty;
l_columnidsource = 0;
l_columnidtarget = 0;
}
public bool setter(s_columninfo columninfo)
{
s_name = columninfo.s_name;
s_dbname = columninfo.s_dbname;
l_columnidsource = columninfo.l_columnidsource;
l_columnidtarget= columninfo.l_columnidtarget;
return true;
}
public bool test()
{
return true;
}
}
}
We then used the DLL importer and built the wrapper code to make calls into the C# DLL. BTW there were no errors identified by the .DLL importer.
The following PowerBuilder code works:
//Declare and Create the .NET assembly wrapper
nvo_s_columninfo lnv_s_columninfo
lnv_s_columninfo = create nvo_s_columninfo
//create the .NET object
boolean b
b = lnv_s_columninfo.of_createondemand()
//passing in the individual elements of the structure works fine
//we can see everything in the SnapDevelop debugger.
lnv_s_columninfo.set_s_dbname("dbname")
lnv_s_columninfo.set_s_name("name")
lnv_s_columninfo.set_l_columnidsource(1)
lnv_s_columninfo.set_l_columnidtarget(1)
//The following code doesn't work for us.
//We can't seem to pass the structure in entirety, and by the time it gets to the .NET assembly it is null.
nvo_s_columninfo lnv_s_columninfo
lnv_s_columninfo = create nvo_s_columninfo
//declare our structure
s_columninfo sc;
//create our .NET wrapper
boolean b
b = lnv_s_columninfo.of_createondemand()
//populate the structure
sc.s_dbname = "dbname"
sc.s_name = "name"
sc.l_columnidsource = 1
sc.l_columnidtarget = 1
//pass the structure into the assmebly
lnv_s_columninfo.setter(sc)
//in the .NET debugger the structure passed in by PB is seen as Null in C#
//The setter method in the C# DLL has received a null value for s_columninfo
Any suggesions would be appreciated. What is possible when passing structures into .NET?
Regardless, it would be a great enhancement to the .NET DLL importer to be able to pass in structures as long as the underlying datatypes in the structure map cleanly. Our intent was to use .NET to serialize a relatively complex structure as JSON, which can be done in about 3 lines of code in .NET. While having DWs describe themselves as JSON is great, it's a partial solution to a larger problem.
Another cool feature for future PB releases would be to allow a PowerObject to be serialized as JSON w/o doing a ton of work to accomplish it. So JSON serialize/deserialize methods for PowerObjects would bring the language in line with .NET CORE and/or NewtonSoft.