private DataType ParseEdmType() { JsonToken jsonToken = PopToken(); if (jsonToken.Type != JsonTokenType.String || jsonToken.GetStringValue() != "$t") { ThrowFormatException("Expecting type marker but found '{0}'", jsonToken.Type.ToString()); } Expect(JsonTokenType.Colon); Expect(JsonTokenType.Number); double doubleValue = currentToken.GetDoubleValue(); if (doubleValue % 1.0 != 0.0 || !edmTypeValues.Contains((int)doubleValue)) { ThrowFormatException("Invalid Edm type: {0}", doubleValue); } int result = (int)doubleValue; Expect(JsonTokenType.Comma); Expect("$v"); Expect(JsonTokenType.Colon); currentToken = PopToken(); currentValue = currentToken; Expect(JsonTokenType.EndObject); return((DataType)result); }
private void Expect(string stringToken) { Expect(JsonTokenType.String); if (currentToken.GetStringValue() != stringToken) { ThrowFormatException("Expecting token {0} but found {1}", stringToken, currentToken.GetStringValue()); } }
public bool MoveNext() { ThrowIfDisposed(); if (state == TableEntityReaderState.Done) { return(false); } JsonToken jsonToken = PopToken(); if (jsonToken.Type == JsonTokenType.EndObject) { state = TableEntityReaderState.Done; return(false); } if (jsonToken.Type == JsonTokenType.String) { currentName = jsonToken.GetStringValue(); } else { ThrowFormatException("Expecting a name but found '{0}'", jsonToken.Lexeme); } Expect(JsonTokenType.Colon); JsonToken jsonToken2 = PopToken(); if (EdmSchemaMapping.IsDocumentDBProperty(currentName) || currentName == "$pk" || currentName == "$id") { switch (jsonToken2.Type) { case JsonTokenType.String: currentEdmType = DataType.String; currentValue = jsonToken2; break; case JsonTokenType.Number: currentEdmType = DataType.Double; currentValue = jsonToken2; break; default: ThrowFormatException("Unexpected value type '{0}' for DocumentDB property.", jsonToken2.Type); break; } } else { if (jsonToken2.Type != JsonTokenType.BeginObject) { ThrowFormatException("Value is expected to be an object instead it was '{0}'.", jsonToken2.Type); } currentEdmType = ParseEdmType(); } TryReadComma(); state = TableEntityReaderState.HasValue; return(true); }
public string ReadString() { ThrowIfDisposed(); ThrowIfInvalidState("ReadString", TableEntityReaderState.HasValue); ThrowIfInvalidType("ReadString", DataType.String); if (currentValue.Type == JsonTokenType.Null) { return(null); } EnsureMatchingTypes(currentValue.Type, JsonTokenType.String); return(currentValue.GetStringValue()); }