Beispiel #1
0
        public void SerializeStaticFields()
        {
            var d = new StaticFieldTestSample();

            StaticFieldTestSample.StaticProperty = 1;
            Json.Manager.SerializeStaticMembers  = true;
            var s = Json.ToJson(d);

            Console.WriteLine(s);
            Assert.IsFalse(s.Contains(@"""MaxValue"":"));
            StringAssert.Contains(s, @"""StaticProperty"":");
            StaticFieldTestSample.StaticProperty = 2;
            StaticFieldTestSample.ChangeReadOnlyProperty();
            var o = Json.ToObject <StaticFieldTestSample> (s);

            Assert.AreEqual(1, StaticFieldTestSample.StaticProperty);
            Assert.AreEqual(3, StaticFieldTestSample.StaticReadOnlyProperty);
            s = Json.ToJson(d, new SerializationManager()
            {
                UseExtensions          = false,
                SerializeStaticMembers = false
            });
            Assert.AreEqual("{}", s);
            Console.WriteLine(s);
            Console.WriteLine(Json.ToJson(d));
            o = Json.ToObject <StaticFieldTestSample> (@"{""MaxValue"":35}");
            Assert.AreEqual(30, StaticFieldTestSample.MaxValue);
            Console.WriteLine(Json.ToJson(o));
            s = Json.ToJson(d, new SerializationManager()
            {
                UseExtensions               = false,
                SerializeStaticMembers      = true,
                SerializeReadOnlyProperties = true,
                SerializeReadOnlyFields     = true
            });
            StringAssert.Contains(s, @"""MaxValue"":");
            StringAssert.Contains(s, @"""StaticProperty"":");
            Assert.AreEqual(30, StaticFieldTestSample.MaxValue);
            Console.WriteLine(s);
        }
Beispiel #2
0
        public void SerializeStaticFields()
        {
            var d = new StaticFieldTestSample();

            StaticFieldTestSample.StaticProperty = 1;
            var s = JSON.ToJSON(d, _JP);

            Console.WriteLine(s);
            Assert.IsFalse(s.Contains(@"""MaxValue"":"));
            StringAssert.Contains(s, @"""StaticProperty"":");
            StaticFieldTestSample.StaticProperty = 2;
            StaticFieldTestSample.ChangeReadOnlyProperty();
            var o = JSON.ToObject <StaticFieldTestSample> (s);

            Assert.AreEqual(1, StaticFieldTestSample.StaticProperty);
            Assert.AreEqual(3, StaticFieldTestSample.StaticReadOnlyProperty);
            s = JSON.ToJSON(d, new JSONParameters()
            {
                UseExtensions          = false,
                SerializeStaticMembers = false
            });
            Assert.AreEqual("{}", s);
            Console.WriteLine(s);
            Console.WriteLine(JSON.ToJSON(d, _JP));
            o = JSON.ToObject <StaticFieldTestSample> (@"{""MaxValue"":35}");
            Assert.AreEqual(30, StaticFieldTestSample.MaxValue);
            Console.WriteLine(JSON.ToJSON(o, _JP));
            s = JSON.ToJSON(d, new JSONParameters()
            {
                UseExtensions          = false,
                SerializeStaticMembers = true,
                ShowReadOnlyProperties = true,
                ShowReadOnlyFields     = true
            });
            StringAssert.Contains(s, @"""MaxValue"":");
            StringAssert.Contains(s, @"""StaticProperty"":");
            Assert.AreEqual(30, StaticFieldTestSample.MaxValue);
            Console.WriteLine(s);
        }