我有我試圖序列化對象,並且輸出看起來是這樣的:XmlIgnore不工作
<root>
<Items>
<Item>
<Value> blabla </Value>
</Item>
</Items>
,其中一項是類,類根用途。
[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);
但該值仍寫在輸出。
我在做什麼錯?
你可以添加Item類嗎? – 2011-03-10 13:05:07
注意事項:在.NET中處理Xml序列化時,'[Serializable]'屬性沒有意義。 – Cheeso 2011-03-10 15:29:38