Note that there are some explanatory texts on larger screens.

plurals
  1. POOverriding a property with an attribute
    primarykey
    data
    text
    <p>I'm trying to find a way to change the serialization behavior of a property.</p> <p>Lets say I have a situation like this:</p> <pre><code>[Serializable] public class Record { public DateTime LastUpdated {get; set; } // other useful properties ... } public class EmployeeRecord : Record { public string EmployeeName {get; set; } // other useful properties ... } </code></pre> <p>Now I want to serialize EmployeeRecord. I don't want the LastUpdated property from the Record class to be serialized. (I do want LastUpdated to be serialized when I serialize Record, though).</p> <p>First I tried hiding the LastUpdated property by using the <em>new</em> keyword and then adding the XmlIgnore attribute:</p> <pre><code>public class EmployeeRecord : Record { public string EmployeeName {get; set; } [XmlIgnore] public new DateTime LastUpdated {get; set; } // other useful properties ... } </code></pre> <p>But that didn't work. Then I tried making the base LastUpdated virtual and overriding it, keeping the attribute:</p> <pre><code>[Serializable] public class Record { public virtual DateTime LastUpdated {get; set; } // other useful properties ... } public class EmployeeRecord : Record { public string EmployeeName {get; set; } [XmlIgnore] public override DateTime LastUpdated {get; set; } // other useful properties ... } </code></pre> <p>This didn't work either. In both attempts the LastUpdated ignored the XmlIgnore attribute and happily went about its business of serializing.</p> <p>Is there a way to make what I'm trying to do happen?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload