Example #1
0
        public void AsDynamicTest()
        {
            JsonValue jv2 = 3;

            Assert.IsTrue(jv2.AsDynamic() == 3);
            Assert.IsTrue(3 == (int)jv2.AsDynamic());
            Assert.IsTrue((JsonValue)3 == jv2.AsDynamic());

            ExceptionTestHelper.ExpectException <Microsoft.CSharp.RuntimeBinder.RuntimeBinderException>(delegate { bool b = 3 == jv2.AsDynamic(); });
        }
    public JsonResult A([DynamicJson] JsonValue value)
    {
        dynamic t = value.AsDynamic();

        if (t.Name.IsEmpty())
        {
            t = new // t is dynamic, so I figure just create the structure you need directly
            {
                Name = "myname",
                D    = new // Associative array notation (woot!):
                {
                    a = "a",
                    b = "b",
                    c = "c"
                }
            };
        }

        return(Json(t));
    }