Serialize and deserialize in Grasshopper

Hi all,
to serialize geometry in grasshopper i use the following method.

public byte[] ObjectToByteArray(object obj)
  {
    if (obj == null)
      return null;
    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);
    return ms.ToArray();
  }

This works greate but only for geometry of type Rhino.Geometry .
and not for Grasshopper.Kernel.Types.
For Grasshopper.Kernel.Types there is the following option.

    GH_Curve ghGeo = new GH_Curve(geo);
    GH_LooseChunk chunk = new GH_LooseChunk("curve");
    ghGeo.Write(chunk);
    A = chunk.Serialize_Binary();

BUT the big problem is that i have to analyse what kind of object do i have to serialze.

The question is.
Is there a way to serialize any kind of Grasshopper.Kernel.Types without getting more specific ?.
Or can i get in visual studio from the tree Rhino.Geometry instead of Grasshopper.Kernel.Types?.

protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool Execute = false;
            GH_Structure<IGH_Goo> Table;
            

            if (!DA.GetData(0, ref Execute)) return;
            if (!DA.GetDataTree<IGH_Goo>(1, out Table)) return;

            if (Execute)
            {
                for (int i = 0; i < Table.DataCount; i++)
                {
                    for (int j = 0; j < Table.get_Branch(i).Count; j++)
                    {
                        // Do i need e specific type or is there GH_Generic ??? data =Table.get_Branch(i)[j];
                        GH_LooseChunk chunk = new GH_LooseChunk("geo" + j.ToString());
                        // This works only for GH_types data.Write(chunk);
                        byte[] b = chunk.Serialize_Binary();

                    }
                }
            }
        }

Any help and clarification is welcome.