Exemple #1
0
        public void WithSubDocumentsAndConversionAccessors()
        {
            // http://stackoverflow.com/questions/2954531/lots-of-first-chance-microsoft-csharp-runtimebinderexceptions-thrown-when-dealin
            dynamic obj = new JSONDynamicObject(JSONDynamicObjectKind.Map);

            obj.type               = "abc";
            obj.startDate          = "5/15/2001 6:00pm";
            obj.target             = new JSONDynamicObject(JSONDynamicObjectKind.Map);
            obj.target.id          = "A678";
            obj.target.image       = "hello";
            obj.target.type        = "good";
            obj.target.description = "Thank You";
            obj.target.Age         = 123;
            obj.target.Salary      = 125000m;


            string s1 = obj.ToJSON();

            var ro1 = s1.JSONToDynamic();

            Assert.AreEqual("abc", ro1.type);
            Assert.AreEqual(new DateTime(2001, 5, 15, 18, 00, 00), ((string)ro1.startDate).AsDateTime());
            Assert.AreEqual("A678", ro1.target.id);
            Assert.AreEqual("hello", ro1.target.image);
            Assert.AreEqual("good", ro1.target.type);
            Assert.AreEqual("Thank You", ro1.target.description);

            Assert.AreEqual(123, ro1.target.Age);

            Assert.AreEqual(125000, ro1.target.Salary);


            string s2 = ((object)obj).ToJSON();

            var ro2 = s2.JSONToDynamic();

            Assert.AreEqual("abc", ro2.type);
            Assert.AreEqual(new DateTime(2001, 5, 15, 18, 00, 00), ((string)ro2.startDate).AsDateTime());
            Assert.AreEqual("A678", ro2.target.id);
            Assert.AreEqual("hello", ro2.target.image);
            Assert.AreEqual("good", ro2.target.type);
            Assert.AreEqual("Thank You", ro2.target.description);
        }
Exemple #2
0
        public void WithSubDocumentsAndConversionAccessors()
        {
            dynamic obj = new JSONDynamicObject(JSONDynamicObjectKind.Map);

            obj.type               = "abc";
            obj.startDate          = "5/15/2001 6:00pm";
            obj.target             = new JSONDynamicObject(JSONDynamicObjectKind.Map);
            obj.target.id          = "A678";
            obj.target.image       = "hello";
            obj.target.type        = "good";
            obj.target.description = "Thank You";
            obj.target.Age         = 123;
            obj.target.Salary      = 125000m;


            string s1 = obj.ToJSON();

            var ro1 = s1.JSONToDynamic();

            Assert.AreEqual("abc", ro1.type);
            Assert.AreEqual(new DateTime(2001, 5, 15, 18, 00, 00), ((string)ro1.startDate).AsDateTime());
            Assert.AreEqual("A678", ro1.target.id);
            Assert.AreEqual("hello", ro1.target.image);
            Assert.AreEqual("good", ro1.target.type);
            Assert.AreEqual("Thank You", ro1.target.description);

            Assert.AreEqual(123, ro1.target.Age);

            Assert.AreEqual(125000, ro1.target.Salary);


            string s2 = ((object)obj).ToJSON();

            var ro2 = s2.JSONToDynamic();

            Assert.AreEqual("abc", ro2.type);
            Assert.AreEqual(new DateTime(2001, 5, 15, 18, 00, 00), ((string)ro2.startDate).AsDateTime());
            Assert.AreEqual("A678", ro2.target.id);
            Assert.AreEqual("hello", ro2.target.image);
            Assert.AreEqual("good", ro2.target.type);
            Assert.AreEqual("Thank You", ro2.target.description);
        }