/// <summary> /// 对象的序列化操作 /// </summary> void Write() { Log.L("类中对字段添加Attribute可以实现一系列操作:"); Log.L("DataColumnName\t\t将对应标题设置为相应的字符串"); Log.L("DataIgnore\t\t序列化和反序列化时都忽略此项"); Log.L("DataReadColumnIndex\t读取时选择读取对应索引列的数据\n"); Log.L("开始将列表对象序列化到本地:"); Log.L("生成一个列表对象,并序列化到本地csv文件中"); List <HuMan> cs = new List <HuMan>() { new HuMan() { age = 1, sex = "m", Name = "xm", heigth = 0 }, new HuMan() { age = 2, sex = "m1", Name = "xm1", heigth = 0 }, new HuMan() { age = 3, sex = "m2", Name = "xm2", heigth = 0 }, }; var w = DataTableTool.CreateWriter(new System.IO.StreamWriter(path, false), new DataRow(), new DataExplainer()); //这里可以设置分离符 //dot指的是逗号替换的值,quotes是引号替换的值 //分离符主要用于将带有引号和逗号的值隔离出来,一般选用不常用的字符 w.Write(cs); w.Dispose(); Log.L("写入完成"); //非windows系统请注释下面这一句,因为我没体验过其它系统打开文件的方法 System.Diagnostics.Process.Start("notepad", path); //用记事本打开写入的文件 }
void Write() { List <Man> cs = new List <Man>() { new Man() { age = 1, sex = "m", Name = "xm" }, new Man() { age = 2, sex = "m1", Name = "xm1" }, new Man() { age = 3, sex = "m2", Name = "xm2" }, }; var w = DataTableTool.CreateWriter(new System.IO.StreamWriter(path, false), new DataRow(), new DataExplainer()); w.Write(cs); w.Dispose(); }