public void ObjectAtPath()
        {
            // Create and initialize and object then convert it to a dictionary
            var o = new DaObject()
            {
                id = 101, Name = "#101"
            };
            var oDict = Json.Reparse <IDictionary <string, object> >(o);

            // Store that dictionary at a path inside another dictionary
            var dict = new Dictionary <string, object>();

            dict.SetPath("settings.daObject", oDict);

            // Get it back as an object (and update dict to hold an actual DaObject
            var o2 = dict.GetObjectAtPath <DaObject>("settings.daObject");

            // Modify it
            o2.id   = 102;
            o2.Name = "modified";

            // Save the dictionary and make sure we got the change
            var json = Json.Format(dict);

            Assert.Contains("102", json);
            Assert.Contains("modified", json);
        }
示例#2
0
        public void Clone()
        {
            var a = new DaObject()
            {
                id = 101, Name = "#101"
            };
            var b = Json.Clone(a);

            Compare(a, b);
        }
示例#3
0
        public void Reparse()
        {
            var a = new DaObject() { id = 101, Name = "#101" };
            var dict = Json.Reparse<IDictionary<string, object>>(a);

            Assert.AreEqual(dict["id"], 101UL);
            Assert.AreEqual(dict["name"], "#101");

            var b = Json.Reparse<DaObject>(dict);

            Compare(a, b);
        }
示例#4
0
        public void Reparse()
        {
            var a = new DaObject()
            {
                id = 101, Name = "#101"
            };
            var dict = Json.Reparse <IDictionary <string, object> >(a);

            Assert.AreEqual(dict["id"], 101UL);
            Assert.AreEqual(dict["name"], "#101");

            var b = Json.Reparse <DaObject>(dict);

            Compare(a, b);
        }
示例#5
0
        public void DictionaryReparseType()
        {
            // Create and initialize and object then convert it to a dictionary
            var o = new DaObject() { id = 101, Name = "#101" };
            var oDict = Json.Reparse<IDictionary<string, object>>(o);

            // Store that dictionary at a path inside another dictionary
            var dict = new Dictionary<string, object>();
            dict.SetPath("settings.daObject", oDict);

            // Get it back out, but reparse it back into a strongly typed object
            var o2 = dict.GetPath<DaObject>("settings.daObject");
            Assert.AreEqual(o2.id, o.id);
            Assert.AreEqual(o2.Name, o.Name);
        }
        public void DictionaryReparseType()
        {
            // Create and initialize and object then convert it to a dictionary
            var o = new DaObject()
            {
                id = 101, Name = "#101"
            };
            var oDict = Json.Reparse <IDictionary <string, object> >(o);

            // Store that dictionary at a path inside another dictionary
            var dict = new Dictionary <string, object>();

            dict.SetPath("settings.daObject", oDict);

            // Get it back out, but reparse it back into a strongly typed object
            var o2 = dict.GetPath <DaObject>("settings.daObject");

            Assert.Equal(o2.id, o.id);
            Assert.Equal(o2.Name, o.Name);
        }
示例#7
0
        public void ObjectAtPath()
        {
            // Create and initialize and object then convert it to a dictionary
            var o = new DaObject() { id = 101, Name = "#101" };
            var oDict = Json.Reparse<IDictionary<string, object>>(o);

            // Store that dictionary at a path inside another dictionary
            var dict = new Dictionary<string, object>();
            dict.SetPath("settings.daObject", oDict);

            // Get it back as an object (and update dict to hold an actual DaObject
            var o2 = dict.GetObjectAtPath<DaObject>("settings.daObject");

            // Modify it
            o2.id = 102;
            o2.Name = "modified";

            // Save the dictionary and make sure we got the change
            var json = Json.Format(dict);
            Assert.Contains(json, "102");
            Assert.Contains(json, "modified");
        }
示例#8
0
 void Compare(DaObject a, DaObject b)
 {
     Assert.AreEqual(a.id, b.id);
     Assert.AreEqual(a.Name, b.Name);
 }
示例#9
0
 public void Clone()
 {
     var a = new DaObject() { id = 101, Name = "#101" };
     var b = Json.Clone(a);
     Compare(a, b);
 }
示例#10
0
 void Compare(DaObject a, DaObject b)
 {
     Assert.AreEqual(a.id, b.id);
     Assert.AreEqual(a.Name, b.Name);
 }