1#
1.首先定义Model、定义Enum的结构
  1. public enum HelpTextEnum
  2.     {
  3.         Test1,
  4.         Test2,
  5.         Test3,
  6.     }

  7.     [XmlRoot("HelpTextConfig")]
  8.     public class HelpTextConfig
  9.     {
  10.         [XmlElement("HelpTextItem")]
  11.         public List<HelpTextItem> TextList { get; set; }

  12.     }

  13.     public class HelpTextItem
  14.     {
  15.         [XmlAttribute("Key")]
  16.         public HelpTextEnum Key { get; set; }

  17.         [XmlAttribute("Text")]
  18.         public string Text { get; set; }
  19.     }
复制代码
2.新建一个实例并序列化成XML的逻辑代码:
  1. var enumArr = new HelpTextConfig();
  2.             enumArr.TextList = new List<HelpTextItem>();

  3.             var item = new HelpTextItem();
  4.             item.Key = HelpTextEnum.Test1;
  5.             
  6.             item.Text = “萨达撒萨达撒大大”;
  7.             
  8.             enumArr.TextList.Add(item);

  9.             XmlSerialHelper.SerializeObject(@"D:\abc.xml", enumArr);

  10.             HelpTextConfig banks2 = XmlSerialHelper.DeserializeObject<HelpTextConfig>(@"D:\abc.xml");


  11.             int c = banks2.TextList.Count;
复制代码
3.生成的XML格式如下:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <HelpTextConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  3.   <HelpTextItem Key="Test1" Text="撒大大萨达啊" />
  4. </HelpTextConfig>
复制代码
4.大功告成,未来将这个XML自动读取转存CouchBase