client.cs

来自「C# XML序列化源码」· CS 代码 · 共 59 行

CS
59
字号
using System;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace XmlSerializationConfig
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Client
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			ReadPeopleFromConfiguration();

			// wait to exit
			Console.ReadLine();
		}

		/// <summary>
		/// Reads the list of people from the configuration file.
		/// </summary>
		static void ReadPeopleFromConfiguration()
		{
			Person[] personArr = PersonFactory.GetProple();
			foreach(Person p in personArr)
			{
				Console.WriteLine("{0} {1}",p.Firstname,p.Lastname);
			}
		}

		/// <summary>
		/// Simple example to demonstrate what an object would
		/// look like in XML format once it has been serialized. 
		/// </summary>
		static void SimpleSerializationExample()
		{
			// create an instance of the class
			Person p = new Person();
			p.Firstname = "Brady";
			p.Lastname = "Gaster";

			// serialize it
			XmlSerializer ser = new XmlSerializer(typeof(Person));
			StringWriter sw = new StringWriter();
			ser.Serialize(sw,p);

			// show the xml
			Console.WriteLine(sw.ToString());
			sw.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?