概念: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
}
[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
public string education { get; set; }
public static List
{
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
{
List
Unity unity = Unity.GetInstance();
DataTable table = new DataTable();
unity.GetTable(out table);
var experiences = (from experience in table.AsEnumerable()
where experience.Field
select new
{
companyName = experience.Field
seniority = experience.Field
}).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);
}
}

<p>Windows 系统上的 OneDrive 应用程序允许您将文件存储在高达 5 GB 的云上。OneDrive 应用程序中还有另一个功能,它允许用户选择一个选项,是将文件保留在系统空间上还是在线提供,而不占用您的系统存储空间。此功能称为按需文件。在这篇文章中,我们进一步探索了此功能,并解释了有关如何在 Windows 11 电脑上的 OneDrive 中按需使用文件的各种选项。</p><h2>如何使用 On

Django框架是一种用于Web应用程序的Python框架,它提供了一个简单而强大的方式来创建Web应用程序。事实上,Django已经成为当前最受欢迎的PythonWeb开发框架之一,也成为很多公司的首选,包括Instagram和Pinterest。本文将深入探讨Django框架是什么,包括基础概念和重要组件,以及具体代码示例。Django基础概念Djan

作为一个流行的PHP框架,Laravel提供了许多便捷的请求方法来处理不同类型的HTTP请求。其中,Head请求方法是一个比较特殊且常被忽视的方法。在本文中,我们将深入探讨Laravel中Head请求方法的作用、用法和示例代码。什么是Head请求方法?Head请求方法是HTTP协议中定义的一种请求方法,在发送Head请求时,服务器将仅返回请求头信息,而不会返

Go语言是一门由Google开发的编程语言,具有高效、简洁、并发性强等特点。它在语法结构、包管理、高级特性等方面都有很大的优势,因此备受程序员青睐。然而,在实际开发中,很多项目会涉及到与传统的编程语言C进行交互,因此Go语言与C语言的兼容性就显得尤为重要。首先,我们来谈谈Go语言与C语言的兼容性。在Go语言中,可以通过CGo将Go语言与C语言进行交互。CGo

Go语言作为一种现代化的编程语言,以其简洁高效的特性在近年来受到越来越多开发者的喜爱和青睐。其中一个让人独特的地方就是其单线程特性。在传统的多线程编程语言中,开发者通常需要手动管理线程之间的同步和互斥,而在Go语言中,借助其独特的协程(Goroutine)和通信机制(channel),可以方便且高效地实现并发编程。一、Goroutine与单线程:Go语言中的

Golang是一种由谷歌开发的编程语言,其出色的性能和并发特性使其在各种领域中得到了广泛的应用,包括网络编程、大数据处理等。然而,对于一些需要直接操作硬件的领域,比如驱动程序开发,人们可能会开始思考:Golang是否适合用于编写驱动程序呢?本文将深入探讨这个问题,并通过具体的代码示例来展示Golang在驱动程序开发中的应用。首先,让我们来了解一下什么是驱动程

MyBatis(又称为iBatis)是一个流行的Java持久层框架,其设计理念是以SQL为核心,在实现SQL和Java对象的映射过程中提供了方便灵活的操作接口。MyBatis通过XML或注解方式配置SQL语句,并提供了丰富的查询方式,使得开发者可以更加直观地编写数据库操作的代码。本文将深入探讨MyBatis的作用和特点,以及提供具体的代码示例加以说明。作用和

Golang的本质是脚本语言还是编译语言?探讨Golang,也被称为Go语言,是一种由Google开发的静态类型编程语言。自诞生以来,Golang一直备受开发者关注,其优秀的并发性能、简洁的语法和跨平台特性使其在各个领域得到广泛应用。然而,关于Golang到底是脚本语言还是编译语言,却一直存在着争议。脚本语言和编译语言在运行时的不同方式给人们留下了深刻的印象


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

MantisBT
Mantis ialah alat pengesan kecacatan berasaskan web yang mudah digunakan yang direka untuk membantu dalam pengesanan kecacatan produk. Ia memerlukan PHP, MySQL dan pelayan web. Lihat perkhidmatan demo dan pengehosan kami.

Dreamweaver CS6
Alat pembangunan web visual

DVWA
Damn Vulnerable Web App (DVWA) ialah aplikasi web PHP/MySQL yang sangat terdedah. Matlamat utamanya adalah untuk menjadi bantuan bagi profesional keselamatan untuk menguji kemahiran dan alatan mereka dalam persekitaran undang-undang, untuk membantu pembangun web lebih memahami proses mengamankan aplikasi web, dan untuk membantu guru/pelajar mengajar/belajar dalam persekitaran bilik darjah Aplikasi web keselamatan. Matlamat DVWA adalah untuk mempraktikkan beberapa kelemahan web yang paling biasa melalui antara muka yang mudah dan mudah, dengan pelbagai tahap kesukaran. Sila ambil perhatian bahawa perisian ini
