【发布时间】:2015-10-01 21:55:39
【问题描述】:
我正在使用 XmlSerializer 将 xml 文档反序列化为一些类对象。有没有办法将节点的属性反序列化为键/值字典,而不必为每个属性命名属性?示例:
public class Panel {
public Dictionary<string, string> AllAttributes {get;set;}
[XmlElement("image", typeof(Image))]
[XmlElement("panel", typeof(Panel))]
public object[] Items { get; set; }
}
【问题讨论】:
-
How to deserialize element with list of attributes in C# 的答案演示了将
Dictionary<string, string>转换为任意属性列表。
标签: c# xml xml-deserialization