title: Deserialize XML to derived class with same element name?
body: <p>I have XML in a format like so:</p>
  
  <pre><code>&lt;TaskList&gt;
  &lt;Task type="TaskA"/&gt;
  &lt;Task type="TaskB"/&gt;
  &lt;/TaskList&gt;
  </code></pre>
  
  <p>that I am trying to deserialize into classes like so:</p>
  
  <pre><code>public class TaskList
  {
      [XmlElement(ElementName = "Task", Type = typeof(Task))]
      public Task[] Task { get; set; } 
  }
  
  [XmlInclude(typeof(TaskA))]
  [XmlInclude(typeof(TaskB))]
  [XmlRoot(ElementName = "Task")]
  public class Task
  {
      //Common Fields
  }
  
  public class TaskA : Task
  {
      //Specific stuff
  }
  
  public class TaskB : Task
  {
      //Specific stuff
  }
  </code></pre>
  
  <p>Trying to deserialize it:</p>
  
  <pre><code>TaskList taskList = (TaskList)new XmlSerializer(typeof(TaskList)).Deserialize(new StringReader(xmlString));
  </code></pre>
  
  <p>In this configuration it'll give me all of the tasks as the base type "Task". How can I get it to use the derived classes?</p>