Let I've a base class
public class MyClass
{
private bool _success;
public bool Success
{
get { return _success; }
set { _success = value; }
}
}
and a derived class
public class MySubClass : MyClass
{
public string str { get; set; }
}
Question: How can I to serialize MySubClass
to XML
such that there is no <Success>
tag in the serialization result?
[XmlIgnore]
public bool Success
{
get { return _success; }
set { _success = value; }
}
The [XmlIgnore]
attribute tells the serialization process to ignore this attribute.
It will never be serialized so there won't be a node in your serialized XML
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlignore.aspx
To ignore the field only in your subclass, you can override the property from the baseclass.
In your base class (note the virtual
keyword):
public virtual bool Success {get;set;}
In you subclass
[XmlIgnore]
public override bool Success {get;set;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With