Esempio n. 1
0
            static void TokenizeInternal(IJsonReader jsonReader, List <JsonToken> tokenList)
            {
                while (jsonReader.Read())
                {
                    switch (jsonReader.CurrentTokenType)
                    {
                    case JsonTokenType.NotStarted:
                        throw new ArgumentException(string.Format("Got an unexpected JsonTokenType: {0} as an expected token type", jsonReader.CurrentTokenType));

                    case JsonTokenType.BeginArray:
                        tokenList.Add(JsonToken.ArrayStart());
                        break;

                    case JsonTokenType.EndArray:
                        tokenList.Add(JsonToken.ArrayEnd());
                        break;

                    case JsonTokenType.BeginObject:
                        tokenList.Add(JsonToken.ObjectStart());
                        break;

                    case JsonTokenType.EndObject:
                        tokenList.Add(JsonToken.ObjectEnd());
                        break;

                    case JsonTokenType.String:
                        tokenList.Add(JsonToken.String(jsonReader.GetStringValue()));
                        break;

                    case JsonTokenType.Number:
                        tokenList.Add(JsonToken.Number(jsonReader.GetNumberValue()));
                        break;

                    case JsonTokenType.True:
                        tokenList.Add(JsonToken.Boolean(true));
                        break;

                    case JsonTokenType.False:
                        tokenList.Add(JsonToken.Boolean(false));
                        break;

                    case JsonTokenType.Null:
                        tokenList.Add(JsonToken.Null());
                        break;

                    case JsonTokenType.FieldName:
                        tokenList.Add(JsonToken.FieldName(jsonReader.GetStringValue()));
                        break;

                    default:
                        throw new ArgumentOutOfRangeException($"Unknown {nameof(JsonTokenType)}: '{jsonReader.CurrentTokenType}'.");
                    }
                }
            }
Esempio n. 2
0
 protected override void WriteBooleanImpl(bool value)
 {
     Write(JsonToken.Boolean(value));
 }