Exemplo n.º 1
0
        internal static void SkipValue(this JsonReader jsonReader)
        {
            int num = 0;

            do
            {
                switch (jsonReader.NodeType)
                {
                case JsonNodeType.StartObject:
                case JsonNodeType.StartArray:
                    num++;
                    break;

                case JsonNodeType.EndObject:
                case JsonNodeType.EndArray:
                    num--;
                    break;
                }
                jsonReader.ReadNext();
            }while (num > 0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read the json array from the reader.
        /// </summary>
        /// <param name="jsonReader">JsonReader instance.</param>
        /// <param name="inputContext">The input context with all the settings.</param>
        /// <param name="recursionDepth">The recursion depth to start with.</param>
        /// <returns>a list of json objects.</returns>
        private static IEnumerable <object> ReadArrayValue(JsonReader jsonReader, ODataInputContext inputContext, int recursionDepth)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonReader != null, "jsonReader != null");
            Debug.Assert(jsonReader.NodeType == JsonNodeType.StartArray, "jsonReader.NodeType == JsonNodeType.StartArray");
            Debug.Assert(inputContext != null, "inputContext != null");

            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, inputContext.MessageReaderSettings.MessageQuotas.MaxNestingDepth);

            List <object> array = new List <object>();

            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndArray)
            {
                switch (jsonReader.NodeType)
                {
                case JsonNodeType.PrimitiveValue:
                    array.Add(jsonReader.ReadPrimitiveValue());
                    break;

                case JsonNodeType.StartObject:
                    array.Add(ReadObjectValue(jsonReader, /*insideJsonObjectValue*/ false, inputContext, recursionDepth));
                    break;

                case JsonNodeType.StartArray:
                    array.Add(ReadArrayValue(jsonReader, inputContext, recursionDepth));
                    break;

                default:
                    Debug.Assert(false, "We should never have got here - the valid states in array are primitive value or object");
                    return(null);
                }
            }

            jsonReader.ReadEndArray();

            return(array);
        }
 private IEnumerable<object> ReadArrayValue(JsonReader jsonReader)
 {
     this.IncreaseRecursionDepth();
     List<object> list = new List<object>();
     jsonReader.ReadNext();
     while (jsonReader.NodeType != JsonNodeType.EndArray)
     {
         switch (jsonReader.NodeType)
         {
             case JsonNodeType.StartObject:
             {
                 list.Add(this.ReadObjectValue(jsonReader));
                 continue;
             }
             case JsonNodeType.StartArray:
             {
                 list.Add(this.ReadArrayValue(jsonReader));
                 continue;
             }
             case JsonNodeType.PrimitiveValue:
             {
                 list.Add(jsonReader.ReadPrimitiveValue());
                 continue;
             }
         }
         return null;
     }
     jsonReader.ReadEndArray();
     this.DecreaseRecursionDepth();
     return list;
 }
        private IDictionary<string, object> ReadObjectValue(JsonReader jsonReader)
        {
            this.IncreaseRecursionDepth();
            IDictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.Ordinal);
            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndObject)
            {
                string key = jsonReader.ReadPropertyName();
                object obj2 = null;
                switch (jsonReader.NodeType)
                {
                    case JsonNodeType.StartObject:
                        obj2 = this.ReadObjectValue(jsonReader);
                        break;

                    case JsonNodeType.StartArray:
                        obj2 = this.ReadArrayValue(jsonReader);
                        break;

                    case JsonNodeType.PrimitiveValue:
                        obj2 = jsonReader.ReadPrimitiveValue();
                        break;

                    default:
                        return null;
                }
                dictionary.Add(key, obj2);
            }
            jsonReader.ReadEndObject();
            this.DecreaseRecursionDepth();
            return dictionary;
        }
        /// <summary>
        /// Read the json array from the reader.
        /// </summary>
        /// <param name="jsonReader">JsonReader instance.</param>
        /// <returns>a list of json objects.</returns>
        private IEnumerable<object> ReadArrayValue(JsonReader jsonReader)
        {
            Debug.Assert(jsonReader != null, "jsonReader != null");
            Debug.Assert(jsonReader.NodeType == JsonNodeType.StartArray, "jsonReader.NodeType == JsonNodeType.StartArray");

            this.IncreaseRecursionDepth();

            List<object> array = new List<object>();
            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndArray)
            {
                switch (jsonReader.NodeType)
                {
                    case JsonNodeType.PrimitiveValue:
                        array.Add(jsonReader.ReadPrimitiveValue());
                        break;
                    case JsonNodeType.StartObject:
                        array.Add(this.ReadObjectValue(jsonReader));
                        break;
                    case JsonNodeType.StartArray:
                        array.Add(this.ReadArrayValue(jsonReader));
                        break;
                    default:
                        Debug.Assert(false, "We should never have got here - the valid states in array are primitive value or object");
                        return null;
                }
            }

            jsonReader.ReadEndArray();
            this.DecreaseRecursionDepth();

            return array;
        }
        /// <summary>
        /// Reads the json object value from the jsonReader
        /// </summary>
        /// <param name="jsonReader">Json reader to read payload from the wire.</param>
        /// <returns>an instance of IDictionary containing the spatial value.</returns>
        private IDictionary<string, object> ReadObjectValue(JsonReader jsonReader)
        {
            Debug.Assert(jsonReader != null, "jsonReader != null");
            Debug.Assert(jsonReader.NodeType == JsonNodeType.StartObject, "jsonReader.NodeType == JsonNodeType.StartObject");

            this.IncreaseRecursionDepth();

            IDictionary<string, object> jsonValue = new Dictionary<string, object>(StringComparer.Ordinal);
            jsonReader.ReadNext();
            while (jsonReader.NodeType != JsonNodeType.EndObject)
            {
                // read the property name
                string propertyName = jsonReader.ReadPropertyName();

                // read the property value
                object propertyValue = null;
                switch (jsonReader.NodeType)
                {
                    case JsonNodeType.PrimitiveValue:
                        propertyValue = jsonReader.ReadPrimitiveValue();
                        break;
                    case JsonNodeType.StartArray:
                        propertyValue = this.ReadArrayValue(jsonReader);
                        break;
                    case JsonNodeType.StartObject:
                        propertyValue = this.ReadObjectValue(jsonReader);
                        break;
                    default:
                        Debug.Assert(false, "We should never reach here - There should be matching end element");
                        return null;
                }

                jsonValue.Add(propertyName, propertyValue);
            }

            jsonReader.ReadEndObject();
            this.DecreaseRecursionDepth();

            return jsonValue;
        }
Exemplo n.º 7
0
 internal static void ReadStartObject(this JsonReader jsonReader)
 {
     jsonReader.ReadNext(JsonNodeType.StartObject);
 }
Exemplo n.º 8
0
 internal static void ReadStartArray(this JsonReader jsonReader)
 {
     jsonReader.ReadNext(JsonNodeType.StartArray);
 }