Beispiel #1
0
        public void JsonCanSerializeAndDeserializeObjectsWithSuppressedNullsWithNiceFormatting()
        {
            Assert.DoesNotThrow(() =>
            {
                var obj  = new MySampleClass();
                var json = JSON.serializePretty(obj, suppressApexObjectNulls: true);
                Assert.False(string.IsNullOrWhiteSpace(json));
                Assert.AreEqual("{\r\n  \"Age\": 0\r\n}", json);

                var inst = (MySampleClass)JSON.deserialize(json, typeof(MySampleClass));
                Assert.NotNull(inst);
                Assert.AreEqual(obj.Name, inst.Name);
                Assert.AreEqual(obj.Age, inst.Age);
            });
        }
Beispiel #2
0
        public void JsonCanSerializeAndDeserializeObjectsWithIndentedFormatting()
        {
            Assert.DoesNotThrow(() =>
            {
                var obj = new MySampleClass {
                    Name = "Goofy", Age = 85
                };
                var json = JSON.serializePretty(obj);
                Assert.False(string.IsNullOrWhiteSpace(json));
                Assert.AreEqual("{\r\n  \"Name\": \"Goofy\",\r\n  \"Age\": 85\r\n}", json);

                var inst = (MySampleClass)JSON.deserialize(json, typeof(MySampleClass));
                Assert.NotNull(inst);
                Assert.AreEqual(obj.Name, inst.Name);
                Assert.AreEqual(obj.Age, inst.Age);
            });
        }
Beispiel #3
0
        public void JsonCanSerializeAndDeserializeObjectsWithDefaultFormatting()
        {
            Assert.DoesNotThrow(() =>
            {
                var obj = new MySampleClass {
                    Name = "Mickey", Age = 89
                };
                var json = JSON.serialize(obj);
                Assert.False(string.IsNullOrWhiteSpace(json));
                Assert.AreEqual("{\"Name\":\"Mickey\",\"Age\":89}", json);

                var inst = (MySampleClass)JSON.deserialize(json, typeof(MySampleClass));
                Assert.NotNull(inst);
                Assert.AreEqual(obj.Name, inst.Name);
                Assert.AreEqual(obj.Age, inst.Age);
            });
        }
Beispiel #4
0
 public override DataTemplate SelectTemplate(object item, DependencyObject container)
 {
     MySampleClass temp = item as MySampleClass;
     if(temp.Value is bool)
     {
         return BooleanTemplate;
     }
     else if(temp.Value is double)
     {
         return DoubleTemplate;
     }
     else if(temp.Value is string)
     {
         return StringTemplate;
     }
     else
     {
         return base.SelectTemplate(item, container);
     }
     
     // And so on
 }