public virtual void Format(object o, JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            if (JNull.LogicallyEquals(o))
            {
                FormatNull(o, writer);
                return;
            }

            //
            // Handle primitive mapping specially.
            //

            switch (Type.GetTypeCode(o.GetType()))
            {
                case TypeCode.Byte    : FormatByte((byte) o, writer);       return;
                case TypeCode.Int16   : FormatInt16((short) o, writer);     return;
                case TypeCode.Int32   : FormatInt32((int) o, writer);       return;
                case TypeCode.Int64   : FormatInt64((long) o, writer);      return;
                case TypeCode.Decimal : FormatDecimal((decimal) o, writer); return;
                case TypeCode.Single  : FormatSingle((float) o, writer);    return;
                case TypeCode.Double  : FormatDouble((double) o, writer);   return;
                case TypeCode.Boolean : FormatBoolean((bool) o, writer);    return;
                case TypeCode.String  : FormatString((string) o, writer);   return;
            }
                    
            //
            // For all other types, go through a method that can be
            // overridden by subtypes.
            //

            FormatOther(o, writer);
        }
Exemple #2
0
        public void Playback(JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteFromReader(CreatePlayer());
        }
Exemple #3
0
 private static void WritePhoneNumber(JsonWriter writer, string location, string number)
 {
     writer.WriteStartObject();      //  {
     writer.WriteMember("Location"); //      "Location" : 
     writer.WriteString(location);   //          "...", 
     writer.WriteMember("Number");   //      "Number" :
     writer.WriteString(number);     //          "..."
     writer.WriteEndObject();        //  }
 }
Exemple #4
0
        void IJsonExportable.Export(ExportContext context, JsonWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteNull();
        }
        protected virtual void FormatOther(object o, JsonWriter writer)
        {
            //
            // If the value is is JSON-aware then let it do the job.
            //

            IJsonFormattable jsonFormattable = o as IJsonFormattable;

            if (jsonFormattable != null)
            {
                FormatFormattable(jsonFormattable, writer);
                return;
            }

            //
            // If the value is a dictionary then encode it as a JSON
            // object.
            //

            IDictionary dictionary = o as IDictionary;

            if (dictionary != null)
            {
                FormatDictionary(dictionary, writer);
                return;
            }

            //
            // If the value is enumerable then encode it as a JSON
            // array.
            //

            IEnumerable enumerable = o as IEnumerable;

            if (enumerable != null)
            {
                FormatEnumerable(enumerable, writer);
                return;
            }

            //
            // For all other types, write out its string representation as a
            // simple JSON string.
            //
            
            writer.WriteString(Convert.ToString(o, CultureInfo.InvariantCulture));
        }
        public virtual void Process(JsonReader request, JsonWriter response)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            if (response == null)
                throw new ArgumentNullException("response");

            IDictionary requestObject;

            try
            {
                requestObject = ParseRequest(request);
            }
            catch (BadRequestException e)
            {
                requestObject = e.Request as IDictionary;

                WriteResponse(
                    CreateResponse(requestObject, /* result */ null,
                        OnError(e.InnerException, requestObject)),
                    response);

                return;
            }

            IDictionary responseObject = Invoke(requestObject);
            WriteResponse(responseObject, response);
        }
            public void Export(ExportContext context, JsonWriter writer, object source)
            {
                if (context == null) throw new ArgumentNullException("context");
                if (writer == null) throw new ArgumentNullException("writer");
                if (source == null) throw new ArgumentNullException("source");

                object value = _property.GetValue(source);
                
                if (JsonNull.LogicallyEquals(value) || value.Equals(_defaultValue))
                    return;

                writer.WriteMember(_property.Name);
                context.Export(value, writer);
            }
 public override void Export(object value, JsonWriter writer)
 {
     ExportCalled = true;
     base.Export(value, writer);
 }
Exemple #9
0
        protected virtual void Export(ExportContext context, JsonWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteStartObject();
            
            foreach (string name in NameIndexList)
            {
                writer.WriteMember(name);    
                context.Export(InnerHashtable[name], writer);
            }

            writer.WriteEndObject();
        }
 protected virtual void FormatDouble(double value, JsonWriter writer)
 {
     writer.WriteNumber(value.ToString(CultureInfo.InvariantCulture));
 }
        public void Export(JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteStartObject();
            
            foreach (string name in NameIndexList)
            {
                writer.WriteMember(name);    
                writer.WriteValue(InnerHashtable[name]);
            }

            writer.WriteEndObject();
        }
Exemple #12
0
 private static void WriteRssToJson(Channel channel, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteMember("title");
     writer.WriteString(channel.title);
     writer.WriteMember("link");
     writer.WriteString(channel.link);
     writer.WriteMember("items");
     writer.WriteStartArray();
     foreach (Item item in channel.item)
         WriteRssToJson(item, writer);
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
 protected virtual void FormatEnumerable(IEnumerable enumerable, JsonWriter writer)
 {
     writer.WriteArray(enumerable);
 }
Exemple #14
0
        protected virtual void Export(ExportContext context, JsonWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteStartArray();

            foreach (object value in this)
                context.Export(value, writer);

            writer.WriteEndArray();
        }
Exemple #15
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);
 }
Exemple #16
0
 public void Export(object value, JsonWriter writer)
 {
     ExportCalled = true;
     JsonConvert.Export(value, writer);
 }
        public virtual void Format(object o, JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            if (JNull.LogicallyEquals(o))
            {
                FormatNull(o, writer);
                return;
            }

            //
            // Handle primitive mapping specially.
            //

            switch (Type.GetTypeCode(o.GetType()))
            {
                case TypeCode.Byte    : FormatByte((byte) o, writer);       return;
                case TypeCode.Int16   : FormatInt16((short) o, writer);     return;
                case TypeCode.Int32   : FormatInt32((int) o, writer);       return;
                case TypeCode.Int64   : FormatInt64((long) o, writer);      return;
                case TypeCode.Decimal : FormatDecimal((decimal) o, writer); return;
                case TypeCode.Single  : FormatSingle((float) o, writer);    return;
                case TypeCode.Double  : FormatDouble((double) o, writer);   return;
                case TypeCode.Boolean : FormatBoolean((bool) o, writer);    return;
                case TypeCode.String  : FormatString((string) o, writer);   return;
            }
                    
            //
            // If the value is is JSON-aware then let it do the job.
            //

            IJsonFormattable jsonFormattable = o as IJsonFormattable;

            if (jsonFormattable != null)
            {
                FormatFormattable(jsonFormattable, writer);
                return;
            }

            //
            // If the value is a dictionary then encode it as a JSON
            // object.
            //

            IDictionary dictionary = o as IDictionary;

            if (dictionary != null)
            {
                FormatDictionary(dictionary, writer);
                return;
            }

            //
            // If the value is enumerable then encode it as a JSON
            // array.
            //

            IEnumerable enumerable = o as IEnumerable;

            if (enumerable != null)
            {
                FormatEnumerable(enumerable, writer);
                return;
            }

            //
            // For all other types, write out its string representation as a
            // simple JSON string.
            //

            FormatCustom(o, writer);
        }
 protected virtual void FormatString(string value, JsonWriter writer)
 {
     writer.WriteString(value);
 }
 protected virtual void FormatBoolean(bool value, JsonWriter writer)
 {
     writer.WriteBoolean(value);
 }
        protected virtual void WriteResponse(IDictionary response, JsonWriter output)
        {
            if (response == null)
                throw new ArgumentNullException("response");

            if (output == null)
                throw new ArgumentNullException("output");

            JsonExporter(response, output);
        }
Exemple #21
0
 //
 // NOTE: For sake of brevity, the following WriteRss* methods do not
 // write out all the members of the RichSiteSummary and related types.
 //
 private static void WriteRssToJson(RichSiteSummary rss, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteMember("version");
     writer.WriteString(rss.version);
     writer.WriteMember("channel");
     WriteRssToJson(rss.channel, writer);
     writer.WriteEndObject();
 }
Exemple #22
0
 public void Init()
 {
     _writer = new EmptyJsonWriter();
 }
Exemple #23
0
 private static void WriteRssToJson(Item item, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteMember("title");
     writer.WriteString(item.title);
     writer.WriteMember("description");
     writer.WriteString(item.description);
     writer.WriteMember("link");
     writer.WriteString(item.link);
     writer.WriteEndObject();
 }
Exemple #24
0
 public void SubExport(ExportContext context, JsonWriter writer)
 {
     Export(context, writer);
 }
        /// <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 Format(JsonWriter writer)
        {
            writer.WriteArray(this);
        }
 protected virtual void FormatInt64(long value, JsonWriter writer)
 {
     writer.WriteNumber(value.ToString(CultureInfo.InvariantCulture));
 }
        public virtual void Format(JsonWriter writer)
        {
            writer.WriteStartObject();
            
            foreach (string name in _nameIndexList)
            {
                writer.WriteMember(name);    
                writer.WriteValue(InnerHashtable[name]);
            }

            writer.WriteEndObject();
        }
Exemple #28
0
 public void Export(JsonWriter writer)
 {
     Export(new ExportContext(), writer);
 }
        public void Export(ExportContext context, JsonWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (writer == null)
                throw new ArgumentNullException("writer");
            
            writer.WriteNumber(Value);
        }
Exemple #30
0
 void IJsonExportable.Export(ExportContext context, JsonWriter writer)
 {
     Export(context, writer);
 }