老熟女激烈的高潮_日韩一级黄色录像_亚洲1区2区3区视频_精品少妇一区二区三区在线播放_国产欧美日产久久_午夜福利精品导航凹凸

重慶分公司,新征程啟航

為企業提供網站建設、域名注冊、服務器等服務

如何使用XMLSerialize序列化與反序列化-創新互聯

這篇文章給大家分享的是有關如何使用XMLSerialize序列化與反序列化的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

成都創新互聯長期為成百上千家客戶提供的網站建設服務,團隊從業經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態環境。為宜興企業提供專業的成都網站建設、成都網站制作宜興網站改版等技術服務。擁有十多年豐富建站經驗和眾多成功案例,為您定制開發。

概念:XML序列化是將公共字段和屬性轉化為序列格式(這里指XML),以便存儲或傳輸的過程。反序列化則是從XML中重新創建原始狀態的對象.


代碼如下:


    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 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 { get; set; }
        public string education { get; set; }
        public static List Employees()
        {
           return new List()
           {
                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 GetWorkExperience(string userId)
        {
            List workExperience = new List();
            Unity unity = Unity.GetInstance();
            DataTable table = new DataTable();
            unity.GetTable(out table);

            var experiences = (from experience in table.AsEnumerable()
                               where experience.Field("UserId") == userId
                               select new
                               {
                                   companyName = experience.Field("CompanyName"),
                                   seniority = experience.Field("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);
        }
    }


感謝各位的閱讀!關于“如何使用XMLSerialize序列化與反序列化”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!


標題名稱:如何使用XMLSerialize序列化與反序列化-創新互聯
當前URL:http://www.xueling.net.cn/article/cedjcs.html

其他資訊

在線咨詢
服務熱線
服務熱線:028-86922220
TOP
主站蜘蛛池模板: 四虎永久在线精品免费无码 | 国产毛片毛片毛片毛片毛片毛片 | 邻居少妇张开腿让我爽了一夜 | 国产精品永久久久久久久久久 | 国产三级欧美三级 | 麻豆专媒体一区二区 | 2002亚洲精品真实在线 | 色香蕉成人二区免费 | 久久不见久久见免费影院视频观看 | 国产交换视频 | 精品一区二区三区蜜桃 | 成人h动漫无码网站久久 | 亚洲国产一 | 日本阿v视频免费观看在线播放 | 视频一区视频二区欧美 | 亚洲国产精品无码久久久久久曰 | 91精品国产综合久久小美女 | 日本污视频 | 成人免费观看高清视频 | 亚洲精品无码鲁网午夜 | 无码国产精品一区二区免费虚拟VR | 亚洲精品乱码久久久久久蜜桃动漫 | 伊人久久一区二区三区 | 做爰全过程免费120秒 | 成人免费视频xbxb入口 | 成人在线欧美 | 欧美日韩亚洲中文 | 久久综合久色欧美综合狠狠 | 国产麻花豆剧传媒精品mv在线 | 欧美日韩性生活片 | 国产手机精品一区二区 | 国产果冻豆传媒麻婆 | 国产成人午夜福利在线播放 | 99手机在线视频 | 天天做天天爱夜夜爽导航 | 久草av网 | 在线无码中文字幕415 | 超碰97在线看| 爱性久久久久久久 | 亚洲中文字幕无码一区日日添 | 9277在线观看免费播放 |