I'm using XmlSerializer to deserialize an xml document into some class objects. Is there a way to deserialize a node's attributes into a dictionary of key/values rather than having to name properties for each attribute? Example:
public class Panel {
public Dictionary<string, string> AllAttributes {get;set;}
[XmlElement("image", typeof(Image))]
[XmlElement("panel", typeof(Panel))]
public object[] Items { get; set; }
}
You have two options:
Implement your own serializer.
Implement a mapping function:
XmlSerializer
to deserialize to a temporary variable (eg var temp
) instead of directly into your class. temp
. This function creates a new instance of your Panel
class, then loops through the temp
properties and maps them to this instance, and finally it returns the new instance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.