title: Extensible text based serialization for c#
body: <p>I'm looking for a text-based (i.e. human readable and not binary) extensible serialization for C#.</p>
  
  <p>The number of items I want to save is rather small (&lt;100). It would be ok to create additional classes for serialization that fill the really used classes after deserialization.</p>
  
  <p>Standard built-in XML serialization is neither very easy to read and neither extensible I think.</p>
  
  <p>I already looked at protobuf-net and it looked promising but since it's binary I dropped it.</p>
  
  <p>I also tried <a href="http://msdn.microsoft.com/en-us/library/ty01x675%28VS.80%29.aspx" rel="nofollow">custom serialization</a> but couldn't manage to serialize two of a kind.</p>
  
  <p>I also had a look at JSON.net but it didn't work better than custom serialization.</p>
  
  <p>My data structure right now looks roughly like this:</p>
  
  <pre><code>class ClassIWantToSerialize
  {
      DataContainer A;
      DataContainer B;
      DataContainer C;
      DataContainer D;
      DataContainer E;
      DataContainer F;
      double G;
      double H;
      // other stuff that I don't want to serialize...
  }
  
  
  class DataContainer
  {
     MinorDataContainer A;
     MinorDataContainer B;
     double C;
     double D;
     double E;
     double F;
      // other stuff that I don't want to serialize...
  }
  
  class MinorDataContainer
  {
     double A;
  }
  </code></pre>
  
  <p>The problem arose when I tried to add the second <code>MinorDataStructure</code> (i.e. <code>B</code>) and it complained that it cannot add the same fields twice.</p>
  
  <pre><code>class DataContainer
  {
      public void GetObjectData(SerializationInfo info, StreamingContext context)
      {
          A.GetObjectData(info, context);
          B.GetObjectData(info, context); // error upon calling this line
          info.AddValue("C", C);
          //...
      }
  }
  </code></pre>