我希望在序列化时忽略Dictionary的所有元素,因为这些成员会导致异常
示例类:
public class TestClass{
public string StringTest { get; set; }
public int IntTest { get; set; }
public Dictionary<int, string> someDictionary { get; set; }
}
我尝试了什么(不成功)
XmlAttributeOverrides xOver = new XmlAttributeOverrides();
XmlAttributes attrs = new XmlAttributes();
attrs.XmlIgnore = true;
xOver.Add(typeof(Dictionary<int, string>), attrs);
XmlSerializer serialiser = new XmlSerializer(objectToConvert.GetType(), xOver);
serialiser.Serialize(writer, objectToConvert);
答案 0 :(得分:0)
您是否尝试过这样做。
[XmlIgnore]
public Dictionary<int.string> someDictionary{get;set;}