シリアル化しようとしているオブジェクトがあり、出力は次のようになります。
<root>
<Items>
<Item>
<Value> blabla </Value>
</Item>
</Items>
ここで、Item はクラス ルートが使用するクラスです。
[Serializable]
[XmlType("root")]
public class Root { }
[Serializable]
[XmlInclude(typeof(Item))]
public class Items {}
[Serializable]
public class Item
{
[XmlElement("Value")]
public string DefaultValue { get; set; }
}
場合によっては、値の値を無視したいのですが、このコードがあります
var overrides = new XmlAttributeOverrides();
var attributes = new XmlAttributes { XmlIgnore = true };
attributes.XmlElements.Add(new XmlElementAttribute("Item"));
overrides.Add(typeof(Item), "Value", attributes);
var serializer = new XmlSerializer(typeof(root), overrides);
ただし、値は引き続き出力に書き込まれます。
私は何を間違っていますか?