Esempio n. 1
0
        public void TestSerializer()
        {
            TempTestClass classA = new TempTestClass
            {
                Id   = 1,
                Name = "NNN",
                Arr  = new[] { 1, 2, 3 }
            };

            string json  = SampleJsonSerializer.Serialize(classA, typeof(TempTestClass));
            string json2 = SampleJsonSerializer.Serialize(classA);

            //序列化是否成功
            Assert.True(json == json2);

            TempTestClass classB = SampleJsonSerializer.DeSerialize(json2, typeof(TempTestClass)) as TempTestClass;

            //反序列化是否成功
            Assert.True(Compare(classA, classB) && Compare(classA, classB));

            json   = json.Replace("NNN", "A");
            classB = SampleJsonSerializer.DeSerialize <TempTestClass>(json);
            TempTestClass classC = SampleJsonSerializer.DeSerialize <TempTestClass>(json2);

            //修改json的情况下是否正确
            Assert.False(Compare(classB, classC));
        }
Esempio n. 2
0
 /// <summary>
 /// 保存配置信息
 /// </summary>
 public static void SaveConfig()
 {
     FileHelper.TryWriteAllText("Config.json", SampleJsonSerializer.Serialize(Config));
 }