title: How to serialize interface typed member
body: <p>I have a class that has a property that is defined as interface.
  Users of my class can assign to this property any class implementation that implements the interface.
  I want to be able to load this class state from a textual file on disk. Users should be able to manually modify the xml file, in order to control the application's operation.</p>
  
  <p>If I try to serialize my class, it tells me I cannot serialize an interface.
  I understand that the serializer has no knowledge about the structure of the property's class, knowing only that it implements an interface.</p>
  
  <p>I would have expected it to call GetType on the member, and reflect into the structure of the actual class. Is there a way to achieve this?
  Is there another way to implement my requirement?</p>
  
  <p><strong>Edit</strong>: Clarifying my intentions:
  Lets say I have this class: </p>
  
  <pre><code>class Car
  {
  IEngine engine
  }
  class ElectricEngine : IEngine 
  {
  int batteryPrecentageLeft;
  }
  class InternalCombustionEngine : IEngine 
  {
  int gasLitersLeft;
  }
  </code></pre>
  
  <p>and the class user has a class with </p>
  
  <pre><code>Car myCar = new Car();
  myCar.Engine = new ElectricEngine() {batteryPrecentageLeft= 70};
  </code></pre>
  
  <p>When I serialize the class myCar, I expect the the xml to resemble this:</p>
  
  <pre><code>&lt;Car&gt;
  &lt;Engine&gt;
  &lt;ElectricEngine&gt;
  &lt;batteryPrecentageLeft&gt;70&lt;/batteryPrecentageLeft&gt;
  &lt;/ElectricEngine&gt;
  &lt;Engine&gt;
  &lt;/Car&gt;
  </code></pre>