コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        private void BinarySerTest()
        {
            var testSerilize = new TestSerilize()
            {
                Id = 10, Name = "二进制", List = new List <int>()
                {
                    1, 2, 3, 4
                }
            };

            BinarySerilize(testSerilize);
            DeBinarySerilize();
        }
コード例 #4
0
        private void SerilizeTest()
        {
            var testSerilize = new TestSerilize()
            {
                Id = 10, Name = "小明", List = new List <int>()
                {
                    1, 2, 3, 4
                }
            };

            XmlSerilize(testSerilize);
            DeSerilizeTest();
        }