Serialize Dictionary member to XML elements and data

后端 未结 2 507
孤城傲影
孤城傲影 2021-01-25 19:25

I have a class \'products\' that is serializable to XML. I\'m using the standard System.Xml.Serialization.XmlSerializer to serialize and a XmlWriter \'writer\' object to write t

2条回答
  •  我在风中等你
    2021-01-25 20:07

    Make the dictionary NonSerialized

    [XmlRoot("specifications")]
        public class Specifications
        {
             [NonSerialized]
             Dictionary dict { get; set; }
             [XmlElement("color")]
             string color {get;set;}
             [XmlElement("length")]
             string length { get; set; }
             [XmlElement("width")]
             string width { get; set; }
    
             public Specifications()
             {
                 dict = new Dictionary();
             }
        }

提交回复
热议问题