private bool ReadArrayElementIntoByteArrayReportDone(List <byte> buffer) { switch (this.TokenType) { case JsonToken.None: throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); case JsonToken.Comment: return(false); case JsonToken.Integer: buffer.Add(Convert.ToByte(this.Value, (IFormatProvider)CultureInfo.InvariantCulture)); return(false); case JsonToken.EndArray: return(true); default: throw JsonReaderException.Create(this, "Unexpected token when reading bytes: {0}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)this.TokenType)); } }
public virtual string ReadAsString() { JsonToken contentToken = this.GetContentToken(); switch (contentToken) { case JsonToken.None: case JsonToken.Null: case JsonToken.EndArray: return((string)null); case JsonToken.String: return((string)this.Value); default: if (!JsonTokenUtils.IsPrimitiveToken(contentToken) || this.Value == null) { throw JsonReaderException.Create(this, "Error reading string. Unexpected token: {0}.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)contentToken)); } IFormattable formattable = this.Value as IFormattable; string str; if (formattable != null) { str = formattable.ToString((string)null, (IFormatProvider)this.Culture); } else { Uri uri = this.Value as Uri; str = uri != (Uri)null ? uri.OriginalString : this.Value.ToString(); } this.SetToken(JsonToken.String, (object)str, false); return(str); } }
internal JsonReaderException CreateUnexpectedEndException() { return(JsonReaderException.Create(this, "Unexpected end when reading JSON.")); }
internal static JsonReaderException Create(JsonReader reader, string message) { return(JsonReaderException.Create(reader, message, (Exception)null)); }