最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

探討:使用XMLSerialize 序列化與反序列化

 更新時間:2013年06月08日 17:30:12   作者:  
本篇文章是對使用XMLSerialize 序列化與反序列化進行了詳細的分析介紹,需要的朋友參考下
概念:XML序列化是將公共字段和屬性轉(zhuǎn)化為序列格式(這里指XML),以便存儲或傳輸?shù)倪^程。反序列化則是從XML中重新創(chuàng)建原始狀態(tài)的對象.
復(fù)制代碼 代碼如下:

    class SerializeDemo
    {
        static void Main()
        {
            EmployeeCollection employeeCollection = new EmployeeCollection()
            {
                Employees = Employeer.Employees()
            };
            XmlSerializer serialize = new XmlSerializer(typeof(EmployeeCollection));
            string filePath = @"E:\PProject\Test\Employee.xml";
             SerializeEmployee(serialize, filePath, employeeCollection);
            DeserializeEmployee(serialize, filePath);
        }
        static void SerializeEmployee(XmlSerializer serialize, string filePath, EmployeeCollection employeeCollection)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
            {
                serialize.Serialize(fs, employeeCollection);
            }
        }
        static void DeserializeEmployee(XmlSerializer serialize,string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                EmployeeCollection collection = (EmployeeCollection)serialize.Deserialize(fs);
                collection.Employees.ForEach(e => Console.WriteLine("Name:{0},Gender:{1},Age:{2},Education:{3}", e.userName, e.gender, e.age, e.education));
            }
        }
    }
    [Serializable]
    public class EmployeeCollection
    {
        public List<Employeer> Employees { get; set; }
    }
    [Serializable]
    public class Employeer
    {
        public string userId { get; set; }
        public string userName { get; set; }
        public string gender { get; set; }
        public int age { get; set; }
        public List<WorkExperience> workExperience { get; set; }
        public string education { get; set; }
        public static List<Employeer> Employees()
        {
           return new List<Employeer>()
           {
                new Employeer()
                {  
                    userId = "0001",
                    userName = "guoHu",
                    gender="Man",
                    age=25,education="underGraduate",
                    workExperience = WorkExperience.GetWorkExperience("0001")
                }
           };

        }
    }
    [Serializable]
    public class WorkExperience
    {
        public string userId { get; set; }
        public string companyName { get; set; }
        public string seniority { get; set; }

        public static List<WorkExperience> GetWorkExperience(string userId)
        {
            List<WorkExperience> workExperience = new List<WorkExperience>();
            Unity unity = Unity.GetInstance();
            DataTable table = new DataTable();
            unity.GetTable(out table);

            var experiences = (from experience in table.AsEnumerable()
                               where experience.Field<string>("UserId") == userId
                               select new
                               {
                                   companyName = experience.Field<string>("CompanyName"),
                                   seniority = experience.Field<string>("Seniority")
                               }).ToList();
            experiences.ForEach(e => workExperience.Add(new WorkExperience() { companyName = e.companyName, seniority = e.seniority }));
            return workExperience;
        }
    }
    public class Unity
    {
        public static DataTable tables = new DataTable();
        public static DataRow dr;
        public static DataColumn dc = new DataColumn();
        public static object objLock = new object();
        public static Unity unityInstance;
        private Unity()
        {

        }
        public static Unity GetInstance()
        {
            if (unityInstance == null)
            {
                lock (objLock)
                {
                    if (unityInstance == null)
                    {
                        unityInstance = new Unity();
                    }
                }
            }
            return unityInstance;
        }
        public void GetTable(out DataTable dt)
        {
            unityInstance.CreateTable();

            dr = tables.NewRow();
            dr["UserId"] = "0001";
            dr["CompanyName"] = "WireSoft";
            dr["Seniority"] = "2012.02-2012.05";
            tables.Rows.Add(dr);
            dr = tables.NewRow();
            dr["UserId"] = "0001";
            dr["CompanyName"] = "Jin Xun";
            dr["Seniority"] = "2009.07-2011.02";
            tables.Rows.Add(dr);
            dr = tables.NewRow();
            dr["UserId"] = "0002";
            dr["CompanyName"] = "Hua Wei";
            dr["Seniority"] = "2011.07-";
            tables.Rows.Add(dr);
            dt = tables.Copy();
        }
        public  void CreateTable()
        {
            dc = new DataColumn("UserId", System.Type.GetType("System.String"));
            tables.Columns.Add(dc);
            dc = new DataColumn("companyName", System.Type.GetType("System.String"));
            tables.Columns.Add(dc);
            dc = new DataColumn("seniority", System.Type.GetType("System.String"));
            tables.Columns.Add(dc);
        }
    }

相關(guān)文章

  • 詳解PHP數(shù)組賦值方法

    詳解PHP數(shù)組賦值方法

    這篇文章主要介紹了詳解PHP數(shù)組賦值方法,文章就怎樣創(chuàng)建數(shù)組、怎樣給PHP數(shù)組賦值,文章都做了詳細的介紹和講解,希望對大家有幫助。
    2015-11-11
  • php中l(wèi)aravel調(diào)度執(zhí)行錯誤解決方法

    php中l(wèi)aravel調(diào)度執(zhí)行錯誤解決方法

    在本篇內(nèi)容里小編給大家整理的是一篇關(guān)于php中l(wèi)aravel調(diào)度執(zhí)行錯誤解決方法,對此有興趣的朋友們可以學(xué)習(xí)參考下。
    2021-02-02
  • php+jQuery ajax實現(xiàn)的實時刷新顯示數(shù)據(jù)功能示例

    php+jQuery ajax實現(xiàn)的實時刷新顯示數(shù)據(jù)功能示例

    這篇文章主要介紹了php+jQuery ajax實現(xiàn)的實時刷新顯示數(shù)據(jù)功能,結(jié)合實例形式分析了php結(jié)合jQuery ajax實時刷新讀取顯示數(shù)據(jù)庫數(shù)據(jù)相關(guān)操作技巧,需要的朋友可以參考下
    2019-09-09
  • 11個PHPer必須要了解的編程規(guī)范

    11個PHPer必須要了解的編程規(guī)范

    從設(shè)計之初,PHP被廣泛用于開發(fā)基于Web的應(yīng)用程序。 由于PHP是一種腳本語言,開發(fā)的時候必須遵守一些規(guī)范。
    2014-09-09
  • 解析PHP可變函數(shù)的經(jīng)典用法

    解析PHP可變函數(shù)的經(jīng)典用法

    本篇文章是對PHP可變函數(shù)的經(jīng)典用法進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • PHP遍歷文件夾與文件類及處理類用法實例

    PHP遍歷文件夾與文件類及處理類用法實例

    這篇文章主要介紹了PHP遍歷文件夾與文件類及處理類用法實例,包括了文件及文件夾的遍歷以及清除utf8的bom頭方法,非常實用,需要的朋友可以參考下
    2014-09-09
  • 兼容firefox,chrome的網(wǎng)頁灰度效果

    兼容firefox,chrome的網(wǎng)頁灰度效果

    今天全天下網(wǎng)頁都變灰了對吧,話說我對這種強制行為很不解。哀悼與否在于一個人的內(nèi)心是否善良。表面上的讓網(wǎng)頁沒有顏色,讓視頻網(wǎng)站不能搜索,究竟有多大意義呢?
    2011-08-08
  • PHP 模板高級篇總結(jié)

    PHP 模板高級篇總結(jié)

    PHP 模板高級篇總結(jié)...
    2006-12-12
  • php中define用法實例

    php中define用法實例

    這篇文章主要介紹了php中define用法,實例分析了php使用define定義常量的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • PHP中替換鍵名的簡易方法示例詳解

    PHP中替換鍵名的簡易方法示例詳解

    默認輸出的時候,將數(shù)據(jù)庫字段名作為數(shù)組的鍵名進行輸出,但帶有鍵名的數(shù)據(jù)不能夠滿足未知情況下的操作,下面為大家介紹個不錯的方法可以解決這個問題
    2014-01-01

最新評論

土默特右旗| 大方县| 卓尼县| 资兴市| 兴隆县| 呼玛县| 湄潭县| 昭苏县| 文昌市| 丰城市| 平泉县| 安塞县| 米泉市| 安顺市| 卢氏县| 光泽县| 合肥市| 周宁县| 临泽县| 吴旗县| 钟祥市| 卢氏县| 白水县| 奉节县| 洛阳市| 镇赉县| 珠海市| 滕州市| 永昌县| 双牌县| 且末县| 梅州市| 宜兴市| 香港| 独山县| 开化县| 芷江| 县级市| 左云县| 区。| 安塞县|