I'm doing the following to ignore a couple of elements on serialization only:
public class Parent
{
public SomeClass MyProperty {get;set;}
public List<Child> Children {get;set;}
}
public class Child
{
public SomeClass MyProperty {get;set;}
}
public class SomeClass
{
public string Name {get;set;}
}
XmlAttributes ignore = new XmlAttributes()
{
XmlIgnore = true
};
XmlAttributeOverrides overrides = new XmlAttributeOverrides();
overrides.Add(typeof(SomeClass), "MyProperty", ignore);
var xs = new XmlSerializer(typeof(MyParent), overrides);
The class properties do not have the XmlElement
attribute. The property name also matches the string passed to overrides.Add
.
However, the above is not ignoring the property and it's still serialized.
What am I missing?