title: C# Serialization - Ignore Property Of Parent Class
body: <p>Is it possible to ignore a property of a parent class when serializing a child class into XML? I also want to do this with JSON if possible, but I'd like xml working first if it is doable.</p>
  
  <p>For example, if I have a base class like this:</p>
  
  <pre><code>    [Serializable]
      [DataContract]
      public abstract class BaseClass
      {
          protected string _correlationID;
          private bool _isValid;
  
          /// &lt;summary&gt;
          /// get/set the correlation id
          /// &lt;/summary&gt;
          [DataMember]
          public virtual string CorrelationID
          {
              get{ return _correlationID; }
              set{ _correlationID = value; }
          }
  
          /// &lt;summary&gt;
          /// get/set IsValid
          /// &lt;/summary&gt;
          [DataMember]
          public virtual bool IsValid 
          {
              get { return _isValid; }
              set { _isValid = value; }
          }
      }
  </code></pre>
  
  <p>and a child class like this</p>
  
  <pre><code>    [Serializable]
      [DataContract]
      public class MyClass : BaseClass
      {
          private int _objectId;
          private string _objectName;
  
          /// &lt;summary&gt;
          /// get/set the object id
          /// &lt;/summary&gt;
          [DataMember]
          public int ObjectId 
          { 
              get { return _objectId; }
              set { _objectId = value; }
          }
  
          /// &lt;summary&gt;
          /// get/set the object name
          /// &lt;/summary&gt;
          [DataMember]
          public int ObjectName 
          { 
              get { return _objectName; }
              set { _objectName = value; }
          }
  
          [XmlIgnore]
          public override string CorrelationID
          {
              get{ return _correlationID; }
              set{ _correlationID = value; }
          }       
      }
  </code></pre>
  
  <p>I want the xml to be returned as:</p>
  
  <pre><code>&lt;MyClass&gt;
      &lt;IsValid&gt;true&lt;/IsValid&gt;
      &lt;ObjectId&gt;5&lt;/ObjectId&gt;
      &lt;ObjectName&gt;My Object&lt;/ObjectName&gt;
  &lt;/MyClass&gt;
  </code></pre>
  
  <p>However, if I try to override the virtual property and add the xml ignore attribute to it, the xml as if I didn't specify and attribute:</p>
  
  <pre><code>&lt;MyClass&gt;
      &lt;CorrelationID&gt;12345678910&lt;/CorrelationID&gt;
      &lt;IsValid&gt;true&lt;/IsValid&gt;
      &lt;ObjectId&gt;5&lt;/ObjectId&gt;
      &lt;ObjectName&gt;My Object&lt;/ObjectName&gt;      
  &lt;/MyClass&gt;
  </code></pre>
  
  <p>I've also tried using [IgnoreDataMember], but it results in the same thing. </p>
  
  <p>I am attempting to do this in MVC/Web APIs to start, but I'd like it to also be applicable to WCF if possible.</p>
  
  <p>Any direction would be helpful. Thanks in advance.</p>