title: Xml Deserializer to deserialize any data type
body: <p>Because I haven't found a better way to handle my configuration, I have been using XmlSerializer to serialize a Dictionary (explain that later) containing all the things I want saved. Now that I have gotten more crafty, I have started to build more complex data types. The only problem is that now when I serialize the object, it throws an error because its not a primitive data type. If I make a new serializer for every value, I then cannot load the object back. Is there an easy way around this? Or an easy library for saving and loading any data type.</p>
  
  <p>The Serializable Dictionary. I'm using <code>&lt;string,object&gt;</code> for <code>&lt;T,S&gt;</code></p>
  
  <pre><code>public void ReadXml (System.Xml.XmlReader reader)
  {
   try {
    XmlSerializer deserializerKeys = new XmlSerializer( typeof(T) );
    XmlSerializer deserializerValues = new XmlSerializer( typeof(S) );
    reader.Read();
    while (true) {
     T key = (T)deserializerKeys.Deserialize(reader);
     S val = (S)deserializerValues.Deserialize(reader); // fail :(
     this.Add( key, val );
    }
   } catch ( Exception e ) {
    Console.WriteLine( e.Message );
    Console.WriteLine( e.StackTrace );
   }
  }
  
  
  public void WriteXml (System.Xml.XmlWriter writer)
  {
      // ONE OF THE serializerValues is always commented out
      // Im just showing the two ways I have done this
   XmlSerializer serializerKeys = new XmlSerializer( typeof( T ) );
      // this works for loading but not for saving &gt;.&gt;
   XmlSerializer serializerValues = new XmlSerializer( typeof( S ) );
   foreach ( KeyValuePair&lt;T,S&gt; pair in this ) {
          // this way works with the saving but fails with loading
    XmlSerializer serializerValues = new XmlSerializer(pair.Value.GetType());
    serializerKeys.Serialize( writer, pair.Key );
    serializerValues.Serialize( writer, pair.Value );
   }
  }
  </code></pre>
  
  <p>Then I have another class that is derived from <code>List&lt;SimpleRegex&gt;</code>, it holds all the <code>SimpleRegex</code> objects and a "selected regex". The <code>SimpleRegex</code> is just a class that holds a simpler regex syntax and provides the same sort of methods a normal regex would(match, replace, etc.). That way, normal people can use it. This <code>RegexCollection</code> (the <code>List&lt;SimpleRegex&gt;</code>) is not primitive. That is my problem. Basically, all I want to do is save and load any data type.</p>