title: How to serialize a generic class to XML?
body: <p>Objects of the following class can be serialized to XML as intended, as long as the actual type of the generic field <code>Object</code> is contained in the list of <code>XmlElement</code> attributes: </p>
  
  <pre><code>public class SerializedObject&lt;T&gt; : Serializable where T : Serializable
  {
      [System.Xml.Serialization.XmlElement(Type = typeof(Weapon))]
      [System.Xml.Serialization.XmlElement(Type = typeof(Armor))]
      [System.Xml.Serialization.XmlElement(Type = typeof(QuestItem))]
      public T Object;
  
      public string ObjectId;
      public int ID;
  
      public SerializedObject() { }
  
      public SerializedObject(T _object)
      {
          Object = _object;
          ID = Object.Id;
          ObjectId = Object.ObjectId;
      }
  }
  </code></pre>
  
  <p>The question is: </p>
  
  <p>How can I serialize an object of this class, including the generic field <code>Object</code> without specifiying all possible types for <code>T</code> in <code>XmlElement</code> attributes?</p>