Passing custom class in c#

If your class acts as a data container, you can avoid using a dll in several ways, for example by passing the data in a tuple or anonymous method, for example:

public class SomeClass{
  public object data0;
  public object data1;
  public SomeClass(object D0, object D1){
    data0 = D0; data1 = D1;
  }
  public SomeClass(object A){
    ImportAnonymous(A);
  }
  public object ExportAnonymous(){
    return new {Data0 = data0, Data1 = data1};
  }
  public void ImportAnonymous(object A){
    try{
      Type t = A.GetType(); 
      data0 = t.GetProperty("Data0").GetValue(A, null);
      data1 = t.GetProperty("Data1").GetValue(A, null);
    }catch(Exception e){
      RhinoApp.WriteLine(e.ToString());
    }
  }
}

Emitter:

SomeClass sm = new SomeClass(12, "Hi");
A = sm.ExportAnonymous(); //A is object

Receiver:

SomeClass sm = new SomeClass(x); //x is object
Print(sm.data0 + ", " + sm.data1); //12, Hi
4 Likes