title: How to serialize the base class with derived classes
body: <p>.</p>
  
  <p>Hello,</p>
  
  <p>I have this sample code :</p>
  
  <pre><code>public class Vehicule
  {
      public string Name { get; set; }
      public Brand Brand { get; set; }
  }
  public class Car : Vehicule
  {
      public string Matriculation { get; set; }
  }
  
  
  
  public class Brand
  {
      public string Name { get; set; }
  }
  public class Renault : Brand
  {
      public string Information { get; set; }
  }
  </code></pre>
  
  <p>If I create this instance :</p>
  
  <pre><code>var car = new Car { Name = "Clio", Matriculation = "XXX-XXX", Brand = new Renault { Name = "Renault", Information = "Contact Infos" } };
  </code></pre>
  
  <p>When I serialize this object like that :</p>
  
  <pre><code>var serializer = new XmlSerializer(typeof(Car), new Type[] { typeof(Renault)});
  serializer.Serialize(wr, car);
  </code></pre>
  
  <p>I obtain this :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Car xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Name&gt;Clio&lt;/Name&gt;
    &lt;Brand xsi:type="Renault"&gt;
      &lt;Name&gt;Renault&lt;/Name&gt;
      &lt;Information&gt;Contact Infos&lt;/Information&gt;
    &lt;/Brand&gt;
    &lt;Matriculation&gt;XXX-XXX&lt;/Matriculation&gt;
  &lt;/Car&gt;
  </code></pre>
  
  <p>But, in my project, I don't have to have informations on derived classes, I would like only elements of base classes from this instance like this :</p>
  
  <pre><code>var serializer = new XmlSerializer(typeof(Vehicule));
  serializer.Serialize(wr, car);
  </code></pre>
  
  <p>The Xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Vehicule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;Name&gt;Clio&lt;/Name&gt;
    &lt;Brand&gt;
      &lt;Name&gt;Renault&lt;/Name&gt;
    &lt;/Brand&gt;
  &lt;/Vehicule&gt;
  </code></pre>
  
  <p>Can you please, help me to obtain the good Xml (only with base type Vehicule and Brand) ?</p>
  
  <p>Many thanks</p>