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 NewObjectAtPath()
        {
            // Create a new object at a path
            var dict = new Dictionary<string, object>();
            var o2 = dict.GetObjectAtPath<DaObject>("settings.daObject");

            // Modify it
            o2.id = 103;
            o2.Name = "new guy";

            // Save the dictionary and make sure we got the change
            var json = Json.Format(dict);
            Assert.Contains(json, "103");
            Assert.Contains(json, "new guy");
        }
        public void NewObjectAtPath()
        {
            // Create a new object at a path
            var dict = new Dictionary <string, object>();
            var o2   = dict.GetObjectAtPath <DaObject>("settings.daObject");

            // Modify it
            o2.id   = 103;
            o2.Name = "new guy";

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

            Assert.Contains("103", json);
            Assert.Contains("new guy", json);
        }
示例#4
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");
        }