云顶集团娱4118-4118ccm云顶集团
做最好的网站

XML与目的的连串化与反体系化_php本领_脚本之家,

日期:2019-11-24编辑作者:云顶集团

1.迭代文件的行复制代码 代码如下: public static IEnumerable ReadLines { using (TextReader reader = File.OpenText { string line; if ((line = reader.ReadLine { yield return line; } } } static void Main() { foreach (string line in Iterator.ReadLines { Console.WriteLine; } }2.应用迭代器和谓词对文本中的行开展筛选复制代码 代码如下: public static IEnumerable where(IEnumerable source, Predicate predicate) { if (source == null || predicate == null) { throw new ArgumentNullException(); } return WhereImplemeter; } private static IEnumerable WhereImplemeter(IEnumerable source, Predicate predicate) { foreach { if { yield return item; } } } static void Main() { IEnumerable lines = File.ReadAllLines; Predicate predicate = delegate { return line.StartsWith; }; foreach (string str in where { Console.WriteLine; } }

gettest.php文件: 复制代码 代码如下:

那篇文章首要叙述XML与对象的体系化与反类别化。何况会附着一些粗略的连串化与反类别化方法,供大家使用。借使大家在贰个Web项目中好似此三个类复制代码 代码如下:public class Member { public string Num { get; set; } public string Name { get; set; } } public class Team { public string Name; public List Members { get; set; } }假使我们需求把Team类的二个实例POST到一个U翼虎L,当然,使用Form隐蔽域提交就足以造成该作用。后生可畏旦该Team包罗30条数据吧?为了不同每一种Member,大家得给参数的名字加上后缀。那将要一大串的掩没域来产生:复制代码 代码如下:@model Team

概念:XML系列化是将国有字段和总体性转变为类别格式,以便存款和储蓄或传输的进程。反体系化则是从XML中再一次创造原始状态的对象.复制代码 代码如下: class Serialize德姆o { static void Main() { EmployeeCollection employeeCollection = new EmployeeCollection() { Employees = Employeer.Employees() }; Xml塞里alizer serialize = new XmlSerializer(typeof; string filePath = @"E:PProjectTestEmployee.xml"; SerializeEmployee(serialize, filePath, employeeCollection); DeserializeEmployee; } 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 = serialize.Deserialize; collection.Employees.ForEach(e => Console.WriteLine("Name:{0},Gender:{1},Age:{2},Education:{3}", e.userName, e.gender, e.age, e.education)); } } } [Serializable]XML与目的的连串化与反体系化_php本领_脚本之家,类别化与反连串化_php本事_脚本之家。 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 { userId = "0001", userName = "guoHu", gender="Man", age=25,education="underGraduate", workExperience = WorkExperience.GetWorkExperience } }; } } [Serializable] public class WorkExperience { public string userId { get; set; } public string companyName { get; set; } public string seniority { get; set; } public static List GetWorkExperience { List workExperience = new List(); Unity unity = Unity.GetInstance(); DataTable table = new DataTable(); unity.GetTable; var experiences = (from experience in table.AsEnumerable() where experience.Field == userId select new { companyName = experience.Field, seniority = experience.Field.ToList(); experiences.ForEach(e => workExperience.Add { 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 { if (unityInstance == null) { unityInstance = new Unity(); } } } return unityInstance; } public void GetTable { unityInstance.CreateTable(); dr = tables.NewRow(); dr["UserId"] = "0001"; dr["CompanyName"] = "WireSoft"; dr["Seniority"] = "2012.02-2012.05"; tables.Rows.Add; dr = tables.NewRow(); dr["UserId"] = "0001"; dr["CompanyName"] = "Jin Xun"; dr["Seniority"] = "2009.07-2011.02"; tables.Rows.Add; dr = tables.NewRow(); dr["UserId"] = "0002"; dr["CompanyName"] = "Hua Wei"; dr["Seniority"] = "2011.07-"; tables.Rows.Add; dt = tables.Copy(); } public void CreateTable() { dc = new DataColumn("UserId", System.Type.GetType; tables.Columns.Add; dc = new DataColumn("companyName", System.Type.GetType; tables.Columns.Add; dc = new DataColumn("seniority", System.Type.GetType; tables.Columns.Add; } }

bindec() -- 二进制转变为十进制

get.php文件如下: 复制代码 代码如下:

还敢想象一下假设Team再复杂一些,嵌套再多一些的情事么?呃,尽管你愿意那样传数据,对方看来意气风发坨参数名就够发烧了。大家都精通对象是不能够在互联网中央行政机关接传输的,然而还应该有补救的格局。XML(Extensible Markup Language)可扩展标志语言,本身就被设计用来囤积数据,任何二个对象都足以用XML来描述。以Team类为例:复制代码 代码如下:

decbin() -- 十进制调换为二进制

本文由云顶集团娱4118发布于云顶集团,转载请注明出处:XML与目的的连串化与反体系化_php本领_脚本之家,

关键词:

php自动加运载飞机制的递进拆解深入分析_php本事

大器晚成、引用重回 引用再次回到用在当想用函数找到援用应该被绑定在哪三个变量上面时。不要用重返援用来扩大...

详细>>

empty的实例测量检验详细明白_php本事_脚本之家,

有关 PHP 的 empty 还有 is_null()这多少个函数的用法切磋得早已重重了,而且不菲素材也不见得能说得很驾驭。这里再重...

详细>>

应用php递归落成Infiniti分类,深刻PHP内部存储器相

PHP暗中同意的最大内存使用大小是32M,假诺你真的必要运用超过32M的内部存款和储蓄器能够修改php.ini配置文件的如下配...

详细>>

夏天浅笑,Python3中坚数据类型

Python3字符串 关于我 网名:夏天浅笑、 英文:summertime-wu 签订左券:立德立言、无闻西东 标签: 咸鱼 、 宅男 、 J...

详细>>