private void BinarySerilize(TestSerilize data) { var fs = new FileStream(Application.dataPath + "/test.bytes", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); var bf = new BinaryFormatter(); bf.Serialize(fs, data);//序列化 fs.Close(); }
private void XmlSerilize(TestSerilize data) { var sm = new FileStream(Application.dataPath + "/test.xml", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); var sw = new StreamWriter(sm, Encoding.UTF8); var xml = new XmlSerializer(data.GetType()); //获取需要序列化的类型 xml.Serialize(sw, data); //序列化 sw.Close(); sm.Close(); }
private void BinarySerTest() { var testSerilize = new TestSerilize() { Id = 10, Name = "二进制", List = new List <int>() { 1, 2, 3, 4 } }; BinarySerilize(testSerilize); DeBinarySerilize(); }
private void SerilizeTest() { var testSerilize = new TestSerilize() { Id = 10, Name = "小明", List = new List <int>() { 1, 2, 3, 4 } }; XmlSerilize(testSerilize); DeSerilizeTest(); }