Please show me how to serialize object of type IEnumerable<KeyValuePair<String, Object>>
. This object do not contain custom structs, but it can (not must) contain another objects (values) of type IE开发者_运维百科numerable<KeyValuePair<String, Object>>
. As for simple it is hierarchy of dictionaries or some other generic types. I can write my own walking while serializing, but maybe you'll show me shortest way;)
Thank you!!!
you could try using XmlSerializer provided your "object" is serializable
IEnumerable<KeyValuePair<String, Object>> data = LoadData(); // however you populate your collection
var dataAsList = data.ToList();
XmlSerializer serializer = new XmlSerializer(dataAsList.GetType());
StringWriter sw = new StringWriter();
serializer.Serialize(sw,dataAsList );
var xml = sw.ToString();
...
...
I would do this manually. I wouldn't trust the XML Serializer to make sense of anything like this.
Use LINQ to XML - it's the simplest.
精彩评论