Serialize Dictionary to xml using DataContractSerializer


DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<MeterSetTypeEnum, MeterSet>));
StringBuilder sb 
= new StringBuilder();
XmlWriterSettings settings 
= new XmlWriterSettings();
settings.Indent 
= true;
settings.IndentChars 
= "  ";

using (XmlWriter writer = XmlWriter.Create(sb, settings))
{
serializer.WriteObject(writer, meters.MeterSets);

} 

posted @ 2011-03-31 10:24  EagleFish(邢瑜琨)  阅读(435)  评论(1编辑  收藏  举报