Ejemplo n.º 1
0
        private static JsonReader Export(int?value)
        {
            JsonRecorder  writer  = new JsonRecorder();
            ExportContext context = JsonConvert.CreateExportContext();

            new NullableExporter(typeof(int?)).Export(context, value, writer);
            return(writer.CreatePlayer());
        }
        public void Export()
        {
            var sb       = new StringBuilder();
            var writer   = JsonText.CreateWriter(sb);
            var buffer   = JsonBuffer.From("[42,{x:123,y:456},foo,true,null,false]");
            var exporter = new JsonBufferExporter();

            exporter.Export(JsonConvert.CreateExportContext(), buffer, writer);
            Assert.AreEqual("[42,{\"x\":123,\"y\":456},\"foo\",true,null,false]", sb.ToString());
        }
Ejemplo n.º 3
0
        public void SubClassCannotExportValueWithNullWriter()
        {
            var tuple    = Tuple.Create(42);
            var exporter = new ExportValueTestExporter(tuple.GetType());

            exporter.ForceNullWriter = true;
            var context = JsonConvert.CreateExportContext();
            var writer  = new JsonBufferWriter();

            exporter.Export(context, tuple, writer);
        }
Ejemplo n.º 4
0
        public void Export()
        {
            var     context = JsonConvert.CreateExportContext();
            dynamic obj     = new ExpandoObject();

            obj.num  = 123;
            obj.flag = true;
            obj.str  = "foobar";
            obj.nums = new[] { 123, 456, 789 };
            var json = new StringBuilder();

            new ExpandoObjectExporter().Export(context, obj, JsonText.CreateWriter(json));
            Assert.AreEqual("{\"num\":123,\"flag\":true,\"str\":\"foobar\",\"nums\":[123,456,789]}", json.ToString());
        }
Ejemplo n.º 5
0
        public JsonRpcDispatchScope(JsonRpcDispatcher dispatcher, HttpContext context)
        {
            Debug.Assert(dispatcher != null);
            Debug.Assert(context != null);

            //
            // Setup for local execution if client request is from the same
            // machine. The dispatcher uses this to determine whether to
            // emit a detailed stack trace or not in the event of an error.
            //

            if (HttpRequestSecurity.IsLocal(context.Request))
            {
                dispatcher.LocalExecution = true;
            }

            //
            // Initialize the import and export contexts, which are pooled
            // per-application instance.
            //

            IDictionary appVars = AppVars.Get(context.ApplicationInstance);

            ExportContext expctx = (ExportContext)appVars[typeof(ExportContext)];

            if (expctx == null)
            {
                expctx = JsonConvert.CreateExportContext();
                appVars.Add(typeof(ExportContext), expctx);
            }

            dispatcher.JsonExporter = new JsonExportHandler(expctx.Export);

            ImportContext impctx = (ImportContext)appVars[typeof(ImportContext)];

            if (impctx == null)
            {
                impctx = JsonConvert.CreateImportContext();
                appVars.Add(typeof(ImportContext), impctx);
            }

            dispatcher.JsonImporter = new JsonImportHandler(impctx.Import);

            _impctx = impctx;
            _expctx = expctx;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Make an JSON external form string of this JsonArray. For
        /// compactness, no unnecessary whitespace is added.
        /// </summary>
        /// <remarks>
        /// This method assumes that the data structure is acyclical.
        /// </remarks>

        public virtual void Export(JsonWriter writer)
        {
            Export(JsonConvert.CreateExportContext(), writer);
        }