C# Marshaling user-defined type in C#

Marshaling PIDL parameter type shows how you can set use define object type on RMI parameter, which also works with C#. Unfortunately C# doesn't have global function as C++ does. But it allows static member function(method). Due to this, in PIDL C#, there is a class called Nettention.ProudClr.CMarshaler which includes marshaling functions. Nettention.ProudClr.CMarshaler already includes marshaling methods of basic type such as integer, string and etc. Proxy and stub created by PIDL compiler can perform marshaling through static method of ProudClr.CMarshaler.

In order to marshal user-defined type, you need the following steps.

  • First, create an inheritance class X of Nettention.ProudClr.CMarshaler. Then, add the marshaling methods as shown in below.
public class X : Nettention.ProudClr.Marshaler
{
public static bool Read(Nettention.ProudClr.Message msg, out MyClass value)
{
value = new MyClass();
if ( msg.Read( out value.a) && msg.Read(out value.b) && msg.Read(out value.c))
return true;
return false;
}
public static void Write(Nettention.ProudClr.Message msg, MyClass value)
{
msg.Write(value.a);
msg.Write(value.b);
msg.Write(value.c);
}
}
  • And declare the use of the inheritance class X from PIDL file.
    [marshaler(cs)=X] global C2C 3000 // marshaler for C#
    {
    Foo([in] MyClass a, ...);
    }

Implementation example can be found at Sample codes of using ProudNet in C#.