public static async Task <RavenJToken> LoadAsync(JsonTextReaderAsync reader) { if (reader.TokenType == JsonToken.None) { if (!await reader.ReadAsync().ConfigureAwait(false)) { throw new Exception("Error reading RavenJArray from JsonReader."); } } if (reader.TokenType != JsonToken.StartArray) { throw new Exception("Error reading RavenJArray from JsonReader. Current JsonReader item is not an array: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } if (await reader.ReadAsync().ConfigureAwait(false) == false) { throw new Exception("Unexpected end of json array"); } var ar = new RavenJArray(); RavenJToken val = null; do { switch (reader.TokenType) { case JsonToken.Comment: // ignore comments break; case JsonToken.EndArray: return(ar); case JsonToken.StartObject: val = await RavenJObject.LoadAsync(reader).ConfigureAwait(false); ar.Items.Add(val); break; case JsonToken.StartArray: val = await LoadAsync(reader).ConfigureAwait(false); ar.Items.Add(val); break; default: val = RavenJValue.Load(reader); ar.Items.Add(val); break; } } while (await reader.ReadAsync().ConfigureAwait(false)); throw new Exception("Error reading RavenJArray from JsonReader."); }
public new static RavenJArray Load(JsonReader reader) { ValidationUtils.ArgumentNotNull(reader, "reader"); if (reader.TokenType == JsonToken.None) { if (!reader.Read()) { throw new Exception("Error reading RavenJArray from JsonReader."); } } if (reader.TokenType != JsonToken.StartArray) { throw new Exception("Error reading RavenJArray from JsonReader. Current JsonReader item is not an array: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } if (reader.Read() == false) { throw new Exception("Unexpected end of json array"); } var ar = new RavenJArray(); RavenJToken val = null; do { switch (reader.TokenType) { case JsonToken.Comment: // ignore comments break; case JsonToken.EndArray: return(ar); case JsonToken.StartObject: val = RavenJObject.Load(reader); ar.Items.Add(val); break; case JsonToken.StartArray: val = RavenJArray.Load(reader); ar.Items.Add(val); break; default: val = RavenJValue.Load(reader); ar.Items.Add(val); break; } } while (reader.Read()); throw new Exception("Error reading RavenJArray from JsonReader."); }
/// <summary> /// Loads an <see cref="RavenJObject"/> from a <see cref="JsonReader"/>. /// </summary> /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="RavenJObject"/>.</param> /// <returns>A <see cref="RavenJObject"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns> public new static RavenJObject Load(JsonReader reader) { ValidationUtils.ArgumentNotNull(reader, "reader"); if (reader.TokenType == JsonToken.None) { if (!reader.Read()) { throw new Exception("Error reading RavenJObject from JsonReader."); } } if (reader.TokenType != JsonToken.StartObject) { throw new Exception( "Error reading RavenJObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } if (reader.Read() == false) { throw new Exception("Unexpected end of json object"); } string propName = null; var o = new RavenJObject(); do { switch (reader.TokenType) { case JsonToken.Comment: // ignore comments break; case JsonToken.PropertyName: propName = reader.Value.ToString(); break; case JsonToken.EndObject: return(o); case JsonToken.StartObject: if (!string.IsNullOrEmpty(propName)) { var val = RavenJObject.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; case JsonToken.StartArray: if (!string.IsNullOrEmpty(propName)) { var val = RavenJArray.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; default: if (!string.IsNullOrEmpty(propName)) { var val = RavenJValue.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; } } while (reader.Read()); throw new Exception("Error reading RavenJObject from JsonReader."); }
public static async Task <RavenJToken> LoadAsync(JsonTextReaderAsync reader) { if (reader.TokenType == JsonToken.None) { if (!await reader.ReadAsync().ConfigureAwait(false)) { throw new Exception("Error reading RavenJObject from JsonReader."); } } if (reader.TokenType != JsonToken.StartObject) { throw new Exception( "Error reading RavenJObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } if (await reader.ReadAsync().ConfigureAwait(false) == false) { throw new Exception("Unexpected end of json object"); } string propName = null; var o = new RavenJObject(); do { switch (reader.TokenType) { case JsonToken.Comment: // ignore comments break; case JsonToken.PropertyName: propName = reader.Value.ToString(); if (String.Equals(propName, String.Empty)) { throw new InvalidDataException("Deserializing Json object with empty string as property name is not supported."); } break; case JsonToken.EndObject: return(o); case JsonToken.StartObject: if (!string.IsNullOrEmpty(propName)) { var val = await LoadAsync(reader).ConfigureAwait(false); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; case JsonToken.StartArray: if (!string.IsNullOrEmpty(propName)) { var val = await RavenJArray.LoadAsync(reader).ConfigureAwait(false); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; default: if (!string.IsNullOrEmpty(propName)) { var val = RavenJValue.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; } } while (await reader.ReadAsync().ConfigureAwait(false)); throw new Exception("Error reading RavenJObject from JsonReader."); }