/// <summary> /// Reads the next JSON token value from the source as a <see cref="bool"/>. /// Returns true if the TokenType is JsonTokenType.True and false if the TokenType is JsonTokenType.False. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if trying to get the value of JSON token that is not a boolean (i.e. <see cref="JsonTokenType.True"/> or <see cref="JsonTokenType.False"/>). /// <seealso cref="TokenType" /> /// </exception> public bool GetBooleanValue() { if (TokenType == JsonTokenType.True) { Debug.Assert(ValueSpan.Length == 4); return(true); } else if (TokenType == JsonTokenType.False) { Debug.Assert(ValueSpan.Length == 5); return(false); } else { throw ThrowHelper.GetInvalidOperationException_ExpectedBoolean(TokenType); } }
/// <summary> /// Reads the next JSON token value from the source as a <see cref="bool"/>. /// Returns true if the TokenType is JsonTokenType.True and false if the TokenType is JsonTokenType.False. /// </summary> /// <exception cref="InvalidOperationException"> /// Thrown if trying to get the value of JSON token that is not a boolean (i.e. <see cref="JsonTokenType.True"/> or <see cref="JsonTokenType.False"/>). /// <seealso cref="TokenType" /> /// </exception> public bool GetBooleanValue() { ReadOnlySpan <byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan; if (TokenType == JsonTokenType.True) { Debug.Assert(span.Length == 4); return(true); } else if (TokenType == JsonTokenType.False) { Debug.Assert(span.Length == 5); return(false); } else { throw ThrowHelper.GetInvalidOperationException_ExpectedBoolean(TokenType); } }