Getting Values from a G2 Sequence in C#

Overview

You have established a connection between G2 and a C# application and want to know how to get the values from a G2 sequence in the C# application. This article provides an example of how this can be accomplished. 

Information

The following example assumes that you have already established a connection between your C# application and G2, that allows you to send and receive data. 
 With the following G2 procedure definition:

dotnet() = (sequence)
s: sequence = sequence();
ss: structure;
begin
ss = structure(x: the symbol dotnet);
s = insert-at-end(s, ss);
return s;
end

And the following C# sample code:

var g2Gateway = new G2Gateway();
g2Gateway.G2Location = "localhost:1111"; 
g2Gateway.Connect(true);
string procname = "dotnet";
object[] procedureArgs = new object[] {};
object ret = g2Gateway.Call(procname, ref procedureArgs);
var seq = (object[])ret;
var r0 = seq[0];
G2Structure b = (G2Structure)r0;
var v = b.Values();
g2Gateway.Disconnect();

The value of v will be [“DOTNET”];

If the received data is of type System_object, you can cast the data to a usable type.

Comments

0 comments

Please sign in to leave a comment.