Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void Playback(JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteFromReader(CreatePlayer());
        }
Exemplo n.º 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();        //  }
 }
Exemplo n.º 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();
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 7
0
            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);
 }
Exemplo n.º 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();
        }
Exemplo n.º 10
0
 protected virtual void FormatDouble(double value, JsonWriter writer)
 {
     writer.WriteNumber(value.ToString(CultureInfo.InvariantCulture));
 }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 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();
 }
Exemplo n.º 13
0
 protected virtual void FormatEnumerable(IEnumerable enumerable, JsonWriter writer)
 {
     writer.WriteArray(enumerable);
 }
Exemplo n.º 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();
        }
Exemplo n.º 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);
 }
Exemplo n.º 16
0
 public void Export(object value, JsonWriter writer)
 {
     ExportCalled = true;
     JsonConvert.Export(value, writer);
 }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
 protected virtual void FormatString(string value, JsonWriter writer)
 {
     writer.WriteString(value);
 }
Exemplo n.º 19
0
 protected virtual void FormatBoolean(bool value, JsonWriter writer)
 {
     writer.WriteBoolean(value);
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 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();
 }
Exemplo n.º 22
0
 public void Init()
 {
     _writer = new EmptyJsonWriter();
 }
Exemplo n.º 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();
 }
Exemplo n.º 24
0
 public void SubExport(ExportContext context, JsonWriter writer)
 {
     Export(context, writer);
 }
Exemplo n.º 25
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 Format(JsonWriter writer)
        {
            writer.WriteArray(this);
        }
Exemplo n.º 26
0
 protected virtual void FormatInt64(long value, JsonWriter writer)
 {
     writer.WriteNumber(value.ToString(CultureInfo.InvariantCulture));
 }
Exemplo n.º 27
0
        public virtual void Format(JsonWriter writer)
        {
            writer.WriteStartObject();
            
            foreach (string name in _nameIndexList)
            {
                writer.WriteMember(name);    
                writer.WriteValue(InnerHashtable[name]);
            }

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

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