title: XML deserialization of derived classes
body: <p>How can I create deserialization method that can take an object of class or any of derived classes?</p>
  
  <pre><code>public class Config
  {
      public string appname;
  }
  
  public class CustomConfig1 : Config
  {
      public string CustomConfig1Param1;
      public string CustomConfig1Param2;
  }
  
  public class CustomConfig2 : Config
  {
      public string CustomConfig2Param1;
      public string CustomConfig2Param2;
  }
  </code></pre>
  
  <p>I want to get something like serialization method that defines type of input object:</p>
  
  <pre><code>public string serialize(object obj)
  {
      XmlSerializer serializer = new XmlSerializer(obj.GetType());
      StringWriter serialized = new StringWriter();
      serializer.Serialize(serialized, obj);
      return serialized.ToString();
  }
  </code></pre>
  
  <p>But when I read an XML from DB I can't define the type of object, so I can't pass it to <em>XmlSerializer</em>. It may be the <em>Config</em> object or any of derived classes </p>
  
  <p>Please help. How can I define the type of input object?</p>