Suppose we have a split class "SerializableLabel" from the base class "System.Windows.Controls.
[XmlRoot("SerializableLabel")]
public class SerializableLabel : Label
{
public string foo = "bar";
}
I would like to serialize this class, but ignore ALL properties in the parent class. Ideally, xml would look something like this:
<SerializableLable>
<foo>bar</foo>
</SerializableLable>
How is this achieved?
My first attempt used the typical XmlSerializer approach:
XmlSerializer s = new XmlSerializer(typeof(SerializableLabel));
TextWriter w = new StreamWriter("test.xml");
s.Serialize(w, lbl);
w.Close();
But this throws an exception, because the serializer tries to serialize the property of the base class, which is the interface (ICommand command).
source
share