System\Text\Json\Document\JsonDocument.cs (63)
114internal JsonTokenType GetJsonTokenType(int index)
127Debug.Assert(!isPropertyName || row.TokenType is JsonTokenType.PropertyName);
138CheckExpectedType(JsonTokenType.StartArray, row.TokenType);
149CheckExpectedType(JsonTokenType.StartObject, row.TokenType);
160CheckExpectedType(JsonTokenType.StartArray, row.TokenType);
236if (includeQuotes && row.TokenType == JsonTokenType.String)
258Debug.Assert(row.TokenType == JsonTokenType.PropertyName);
271if (row.TokenType == JsonTokenType.String)
285internal string? GetString(int index, JsonTokenType expectedType)
291JsonTokenType tokenType = row.TokenType;
293if (tokenType == JsonTokenType.Null)
350isPropertyName ? JsonTokenType.PropertyName : JsonTokenType.String,
385return GetString(index - DbRow.Size, JsonTokenType.PropertyName)!;
393Debug.Assert(row.TokenType is JsonTokenType.PropertyName);
404CheckExpectedType(JsonTokenType.String, row.TokenType);
425CheckExpectedType(JsonTokenType.Number, row.TokenType);
447CheckExpectedType(JsonTokenType.Number, row.TokenType);
469CheckExpectedType(JsonTokenType.Number, row.TokenType);
491CheckExpectedType(JsonTokenType.Number, row.TokenType);
513CheckExpectedType(JsonTokenType.Number, row.TokenType);
535CheckExpectedType(JsonTokenType.Number, row.TokenType);
557CheckExpectedType(JsonTokenType.Number, row.TokenType);
579CheckExpectedType(JsonTokenType.Number, row.TokenType);
601CheckExpectedType(JsonTokenType.Number, row.TokenType);
623CheckExpectedType(JsonTokenType.Number, row.TokenType);
645CheckExpectedType(JsonTokenType.Number, row.TokenType);
667CheckExpectedType(JsonTokenType.String, row.TokenType);
702CheckExpectedType(JsonTokenType.String, row.TokenType);
737CheckExpectedType(JsonTokenType.String, row.TokenType);
806case JsonTokenType.StartObject:
810case JsonTokenType.StartArray:
814case JsonTokenType.String:
817case JsonTokenType.Number:
820case JsonTokenType.True:
823case JsonTokenType.False:
826case JsonTokenType.Null:
845case JsonTokenType.String:
848case JsonTokenType.Number:
851case JsonTokenType.True:
854case JsonTokenType.False:
857case JsonTokenType.Null:
860case JsonTokenType.StartObject:
863case JsonTokenType.EndObject:
866case JsonTokenType.StartArray:
869case JsonTokenType.EndArray:
872case JsonTokenType.PropertyName:
883Debug.Assert(row.TokenType == JsonTokenType.String || row.TokenType == JsonTokenType.PropertyName);
914Debug.Assert(row.TokenType == JsonTokenType.PropertyName);
964JsonTokenType tokenType = reader.TokenType;
971if (tokenType == JsonTokenType.StartObject)
985else if (tokenType == JsonTokenType.EndObject)
987int rowIndex = database.FindIndexOfFirstUnsetSizeOrLength(JsonTokenType.StartObject);
1002else if (tokenType == JsonTokenType.StartArray)
1016else if (tokenType == JsonTokenType.EndArray)
1018int rowIndex = database.FindIndexOfFirstUnsetSizeOrLength(JsonTokenType.StartArray);
1048else if (tokenType == JsonTokenType.PropertyName)
1068Debug.Assert(tokenType >= JsonTokenType.String && tokenType <= JsonTokenType.Null);
1077if (tokenType == JsonTokenType.String)
1110private static void CheckExpectedType(JsonTokenType expected, JsonTokenType actual)
System\Text\Json\Reader\Utf8JsonReader.cs (106)
35private JsonTokenType _tokenType;
36private JsonTokenType _previousTokenType;
110if (TokenType is JsonTokenType.StartArray or JsonTokenType.StartObject)
124public readonly JsonTokenType TokenType => _tokenType;
284if (_isFinalBlock && TokenType is JsonTokenType.None && !_readerOptions.AllowMultipleValues)
303/// When <see cref="TokenType"/> is <see cref="JsonTokenType.PropertyName" />, the reader first moves to the property value.
304/// When <see cref="TokenType"/> (originally, or after advancing) is <see cref="JsonTokenType.StartObject" /> or
305/// <see cref="JsonTokenType.StartArray" />, the reader advances to the matching
306/// <see cref="JsonTokenType.EndObject" /> or <see cref="JsonTokenType.EndArray" />.
326if (TokenType is JsonTokenType.PropertyName)
334if (TokenType is JsonTokenType.StartObject or JsonTokenType.StartArray)
362/// When <see cref="TokenType"/> is <see cref="JsonTokenType.PropertyName" />, the reader first moves to the property value.
363/// When <see cref="TokenType"/> (originally, or after advancing) is <see cref="JsonTokenType.StartObject" /> or
364/// <see cref="JsonTokenType.StartArray" />, the reader advances to the matching
365/// <see cref="JsonTokenType.EndObject" /> or <see cref="JsonTokenType.EndArray" />.
403if (TokenType is JsonTokenType.PropertyName)
412if (TokenType is not (JsonTokenType.StartObject or JsonTokenType.StartArray))
440/// (i.e. other than <see cref="JsonTokenType.String"/> or <see cref="JsonTokenType.PropertyName"/>).
470/// (i.e. other than <see cref="JsonTokenType.String"/> or <see cref="JsonTokenType.PropertyName"/>).
511/// (i.e. other than <see cref="JsonTokenType.String"/> or <see cref="JsonTokenType.PropertyName"/>).
690private static bool IsTokenTypeString(JsonTokenType tokenType)
692return tokenType == JsonTokenType.PropertyName || tokenType == JsonTokenType.String;
749_tokenType = JsonTokenType.StartObject;
767_tokenType = JsonTokenType.EndObject;
783_tokenType = JsonTokenType.StartArray;
801_tokenType = JsonTokenType.EndArray;
844if (_tokenType == JsonTokenType.None)
855if (_tokenType == JsonTokenType.StartObject)
876_tokenType = JsonTokenType.StartObject;
883else if (_tokenType == JsonTokenType.StartArray)
895else if (_tokenType == JsonTokenType.PropertyName)
928if (_readerOptions.CommentHandling == JsonCommentHandling.Allow && _tokenType == JsonTokenType.Comment)
933if (_tokenType is not JsonTokenType.EndArray and not JsonTokenType.EndObject)
965_tokenType = JsonTokenType.StartObject;
975_tokenType = JsonTokenType.StartArray;
992_tokenType = JsonTokenType.Number;
1001_isNotPrimitive = _tokenType is JsonTokenType.StartObject or JsonTokenType.StartArray;
1066return ConsumeLiteral(JsonConstants.FalseValue, JsonTokenType.False);
1070return ConsumeLiteral(JsonConstants.TrueValue, JsonTokenType.True);
1074return ConsumeLiteral(JsonConstants.NullValue, JsonTokenType.Null);
1096if (_isNotPrimitive && IsLastSpan && _tokenType != JsonTokenType.EndArray && _tokenType != JsonTokenType.EndObject)
1133private bool ConsumeLiteral(ReadOnlySpan<byte> literal, JsonTokenType tokenType)
1212_tokenType = JsonTokenType.Number;
1275_tokenType = JsonTokenType.PropertyName;
1301_tokenType = JsonTokenType.String;
1400_tokenType = JsonTokenType.String;
1701JsonTokenType prevTokenType = _tokenType;
1733if (_tokenType == JsonTokenType.Comment)
1841Debug.Assert(_tokenType == JsonTokenType.Comment);
1845_tokenType = _inObject ? JsonTokenType.StartObject : JsonTokenType.StartArray;
1852Debug.Assert(_tokenType != JsonTokenType.Comment);
1872if (_bitStack.CurrentDepth == 0 && _tokenType != JsonTokenType.None)
1889if (_previousTokenType <= JsonTokenType.StartObject || _previousTokenType == JsonTokenType.StartArray || _trailingCommaBeforeComment)
1991else if (_tokenType == JsonTokenType.None)
2002else if (_tokenType == JsonTokenType.StartObject)
2017_tokenType = JsonTokenType.StartObject;
2024else if (_tokenType == JsonTokenType.StartArray)
2033else if (_tokenType == JsonTokenType.PropertyName)
2043Debug.Assert(_tokenType is JsonTokenType.EndArray or JsonTokenType.EndObject);
2164if (_tokenType == JsonTokenType.StartObject)
2184_tokenType = JsonTokenType.StartObject;
2192else if (_tokenType == JsonTokenType.StartArray)
2207else if (_tokenType == JsonTokenType.PropertyName)
2530if (_tokenType != JsonTokenType.Comment)
2534_tokenType = JsonTokenType.Comment;
2548if (_tokenType != JsonTokenType.Comment)
2552_tokenType = JsonTokenType.Comment;
2565JsonTokenType.Comment => nameof(JsonTokenType.Comment),
2566JsonTokenType.EndArray => nameof(JsonTokenType.EndArray),
2567JsonTokenType.EndObject => nameof(JsonTokenType.EndObject),
2568JsonTokenType.False => nameof(JsonTokenType.False),
2569JsonTokenType.None => nameof(JsonTokenType.None),
2570JsonTokenType.Null => nameof(JsonTokenType.Null),
2571JsonTokenType.Number => nameof(JsonTokenType.Number),
2572JsonTokenType.PropertyName => nameof(JsonTokenType.PropertyName),
2573JsonTokenType.StartArray => nameof(JsonTokenType.StartArray),
2574JsonTokenType.StartObject => nameof(JsonTokenType.StartObject),
2575JsonTokenType.String => nameof(JsonTokenType.String),
2576JsonTokenType.True => nameof(JsonTokenType.True),
System\Text\Json\ThrowHelper.cs (18)
262public static InvalidOperationException GetInvalidOperationException_ExpectedArray(JsonTokenType tokenType)
267public static InvalidOperationException GetInvalidOperationException_ExpectedObject(JsonTokenType tokenType)
273public static void ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
279public static void ThrowInvalidOperationException_ExpectedBoolean(JsonTokenType tokenType)
285public static void ThrowInvalidOperationException_ExpectedString(JsonTokenType tokenType)
291public static void ThrowInvalidOperationException_ExpectedPropertyName(JsonTokenType tokenType)
297public static void ThrowInvalidOperationException_ExpectedStringComparison(JsonTokenType tokenType)
303public static void ThrowInvalidOperationException_ExpectedComment(JsonTokenType tokenType)
314private static InvalidOperationException GetInvalidOperationException(string message, JsonTokenType tokenType)
319private static InvalidOperationException GetInvalidOperationException(JsonTokenType tokenType)
326JsonTokenType expectedType,
327JsonTokenType actualType)
497public static void ThrowInvalidOperationException(ExceptionResource resource, int currentDepth, int maxDepth, byte token, JsonTokenType tokenType)
572public static InvalidOperationException GetInvalidOperationException(ExceptionResource resource, int currentDepth, int maxDepth, byte token, JsonTokenType tokenType)
588private static string GetResourceString(ExceptionResource resource, int currentDepth, int maxDepth, byte token, JsonTokenType tokenType)
595message = (tokenType == JsonTokenType.PropertyName) ?
612message = (tokenType == JsonTokenType.PropertyName) ?
718public static void ThrowInvalidOperationException_ExpectedChar(JsonTokenType tokenType)