title: How to serialize/deserialize only base class properties with DataContractSerializer?
body: <p>What would be the simplest way of serializing and deserializing the declared types of properties only, ignoring the fact that the actual object is more derived than declared? For instance, with these classes:</p>
  
  <pre><code>[DataContract]
  public class Base
  {
      [DataMember]
      string BaseProperty { get; set; }
  }
  
  public class Derived : Base
  {
      string DerivedProperty { get; set; }
  }
  </code></pre>
  
  <p>I would like to be able to achieve the equivalent of this:</p>
  
  <pre><code>Base baseObject = new Derived();
  var baseSerializer = new DataContractSerializer(typeof(Base));
  
  using (var fileStream = File.OpenWrite("file"))
  using (var writer = XmlDictionaryWriter.CreateBinaryWriter(fileStream))
  {
      baseSerializer.WriteObject(writer, baseObject);
  }
  
  using (var fileStream = File.OpenRead("file"))
  using (var reader = XmlDictionaryReader.CreateBinaryReader(fileStream, new XmlDictionaryReaderQuotas()))
  {
      var deserialized = (Base)baseSerializer.ReadObject(reader);
  }
  </code></pre>
  
  <p>Provided example code fails because <code>Derived</code> is not a known type, of course. But I'm not interested in writing that additional information into a file, only what the base class provides.</p>