예제 #1
0
		/// <summary>
		/// 测试写入数据.
		/// </summary>
		public void TestWrite()
		{
			OrangeStorage storage = new OrangeStorage();
			storage.StorageName = "Test";



			Orange o1 = new Orange(1, "中国", "红", "甜");
			Orange o2 = new Orange(2, "美国", "黄", "酸");


			storage.OrangeArray = new Orange[2];

			storage.OneOrange = o1;

			storage.OrangeArray[0] = o1;
			storage.OrangeArray[1] = o2;


			storage.OrangeList = new List<Orange>();

			storage.OrangeList.Add(o1);
			storage.OrangeList.Add(o2);


			XmlSerializer xs = new XmlSerializer(typeof(OrangeStorage));
			StreamWriter sw = new StreamWriter(FILE_NAME);
			xs.Serialize(sw, storage);
			sw.Close();
		}
예제 #2
0
        /// <summary>
        /// 测试写入数据.
        /// </summary>
        public void TestWrite()
        {
            OrangeStorage storage = new OrangeStorage();

            storage.StorageName = "Test";



            Orange o1 = new Orange(1, "中国", "红", "甜");
            Orange o2 = new Orange(2, "美国", "黄", "酸");


            storage.OrangeArray = new Orange[2];

            storage.OneOrange = o1;

            storage.OrangeArray[0] = o1;
            storage.OrangeArray[1] = o2;


            storage.OrangeList = new List <Orange>();

            storage.OrangeList.Add(o1);
            storage.OrangeList.Add(o2);



            // 输出 UTF-8 的 XML 文件.
            XmlSerializer xs = new XmlSerializer(typeof(OrangeStorage));
            StreamWriter  sw = new StreamWriter(FILE_NAME);

            xs.Serialize(sw, storage);
            sw.Close();



            // 输出 GB2312 的 XML 文件.
            string xml = XmlUtility.XmlSerialize <OrangeStorage>(storage);

            File.WriteAllText(FILE_NAME_GB2312, xml, Encoding.GetEncoding("GB2312"));
        }