private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Text.Json.JsonElement this[int index] { get { throw null; } }
- public System.Text.Json.JsonValueType Type { get { throw null; } }
+ public System.Text.Json.JsonValueKind ValueKind { get { throw null; } }
public System.Text.Json.JsonElement Clone() { throw null; }
public System.Text.Json.JsonElement.ArrayEnumerator EnumerateArray() { throw null; }
public System.Text.Json.JsonElement.ObjectEnumerator EnumerateObject() { throw null; }
Null = (byte)10,
Comment = (byte)11,
}
- public enum JsonValueType : byte
+ public enum JsonValueKind : byte
{
Undefined = (byte)0,
Object = (byte)1,
<Compile Include="System\Text\Json\Document\JsonElement.ArrayEnumerator.cs" />
<Compile Include="System\Text\Json\Document\JsonElement.ObjectEnumerator.cs" />
<Compile Include="System\Text\Json\Document\JsonProperty.cs" />
- <Compile Include="System\Text\Json\Document\JsonValueType.cs" />
+ <Compile Include="System\Text\Json\Document\JsonValueKind.cs" />
<Compile Include="System\Text\Json\Reader\ConsumeNumberResult.cs" />
<Compile Include="System\Text\Json\Reader\ConsumeTokenResult.cs" />
<Compile Include="System\Text\Json\Reader\JsonReaderHelper.cs" />
private JsonTokenType TokenType => _parent?.GetJsonTokenType(_idx) ?? JsonTokenType.None;
/// <summary>
- /// The <see cref="JsonValueType"/> that the value is.
+ /// The <see cref="JsonValueKind"/> that the value is.
/// </summary>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </exception>
- public JsonValueType Type => TokenType.ToValueType();
+ public JsonValueKind ValueKind => TokenType.ToValueKind();
/// <summary>
/// Get the value at a specified index when the current value is a
- /// <see cref="JsonValueType.Array"/>.
+ /// <see cref="JsonValueKind.Array"/>.
/// </summary>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Array"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Array"/>.
/// </exception>
/// <exception cref="IndexOutOfRangeException">
/// <paramref name="index"/> is not in the range [0, <see cref="GetArrayLength"/>()).
/// </summary>
/// <returns>The number of values contained within the current array value.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Array"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Array"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </returns>
/// <seealso cref="EnumerateObject"/>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="KeyNotFoundException">
/// No property was found with the requested name.
/// </returns>
/// <seealso cref="EnumerateObject"/>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="KeyNotFoundException">
/// No property was found with the requested name.
/// A <see cref="JsonElement"/> representing the value of the requested property.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="KeyNotFoundException">
/// No property was found with the requested name.
/// <see langword="true"/> if the property was found, <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="ArgumentNullException">
/// <paramref name="propertyName"/> is <see langword="null"/>.
/// </returns>
/// <seealso cref="EnumerateObject"/>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </returns>
/// <seealso cref="EnumerateObject"/>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </remarks>
/// <returns>The value of the element as a <see cref="bool"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is neither <see cref="JsonValueType.True"/> or
- /// <see cref="JsonValueType.False"/>.
+ /// This value's <see cref="ValueKind"/> is neither <see cref="JsonValueKind.True"/> or
+ /// <see cref="JsonValueKind.False"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </remarks>
/// <returns>The value of the element as a <see cref="string"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is neither <see cref="JsonValueType.String"/> nor <see cref="JsonValueType.Null"/>.
+ /// This value's <see cref="ValueKind"/> is neither <see cref="JsonValueKind.String"/> nor <see cref="JsonValueKind.Null"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </remarks>
/// <returns>The value decode to bytes.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value is not encoded as base 64 text and hence cannot be decoded to bytes.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </summary>
/// <returns>The current JSON number as an <see cref="sbyte"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as an <see cref="sbyte"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// This method does not parse the contents of a JSON string value.
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="byte"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </summary>
/// <returns>The current JSON number as an <see cref="short"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as an <see cref="short"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// This method does not parse the contents of a JSON string value.
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="ushort"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </summary>
/// <returns>The current JSON number as an <see cref="int"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as an <see cref="int"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// This method does not parse the contents of a JSON string value.
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="uint"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// This method does not parse the contents of a JSON string value.
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="long"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// This method does not parse the contents of a JSON string value.
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="ulong"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </para>
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="double"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </para>
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="float"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// This method does not parse the contents of a JSON string value.
/// </remarks>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Number"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="decimal"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </remarks>
/// <returns>The value of the element as a <see cref="DateTime"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="DateTime"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </remarks>
/// <returns>The value of the element as a <see cref="DateTimeOffset"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="DateTimeOffset"/>.
/// <see langword="false"/> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </remarks>
/// <returns>The value of the element as a <see cref="Guid"/>.</returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <exception cref="FormatException">
/// The value cannot be represented as a <see cref="Guid"/>.
/// <see langword="false" /> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <remarks>
/// This method is functionally equal to doing an ordinal comparison of <paramref name="text" /> and
/// <paramref name="utf8Text" />, <see langword="false" /> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <remarks>
/// This method is functionally equal to doing an ordinal comparison of the string produced by UTF-8 decoding
/// <see langword="false" /> otherwise.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.String"/>.
/// </exception>
/// <remarks>
/// This method is functionally equal to doing an ordinal comparison of <paramref name="text" /> and
/// <param name="propertyName">The name for this value within the JSON object.</param>
/// <param name="writer">The writer.</param>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is <see cref="JsonValueType.Undefined"/>.
+ /// This value's <see cref="ValueKind"/> is <see cref="JsonValueKind.Undefined"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// <param name="propertyName">The name for this value within the JSON object.</param>
/// <param name="writer">The writer.</param>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is <see cref="JsonValueType.Undefined"/>.
+ /// This value's <see cref="ValueKind"/> is <see cref="JsonValueKind.Undefined"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// <param name="propertyName">The pre-encoded name for this value within the JSON object.</param>
/// <param name="writer">The writer.</param>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is <see cref="JsonValueType.Undefined"/>.
+ /// This value's <see cref="ValueKind"/> is <see cref="JsonValueKind.Undefined"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </param>
/// <param name="writer">The writer.</param>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is <see cref="JsonValueType.Undefined"/>.
+ /// This value's <see cref="ValueKind"/> is <see cref="JsonValueKind.Undefined"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </summary>
/// <param name="writer">The writer.</param>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is <see cref="JsonValueType.Undefined"/>.
+ /// This value's <see cref="ValueKind"/> is <see cref="JsonValueKind.Undefined"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// An enumerator to enumerate the values in the JSON array represented by this JsonElement.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Array"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Array"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// An enumerator to enumerate the properties in the JSON object represented by this JsonElement.
/// </returns>
/// <exception cref="InvalidOperationException">
- /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// This value's <see cref="ValueKind"/> is not <see cref="JsonValueKind.Object"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The parent <see cref="JsonDocument"/> has been disposed.
/// </summary>
/// <remarks>
/// <para>
- /// For <see cref="JsonValueType.Null"/>, <see cref="string.Empty"/> is returned.
+ /// For <see cref="JsonValueKind.Null"/>, <see cref="string.Empty"/> is returned.
/// </para>
///
/// <para>
- /// For <see cref="JsonValueType.True"/>, <see cref="bool.TrueString"/> is returned.
+ /// For <see cref="JsonValueKind.True"/>, <see cref="bool.TrueString"/> is returned.
/// </para>
///
/// <para>
- /// For <see cref="JsonValueType.False"/>, <see cref="bool.FalseString"/> is returned.
+ /// For <see cref="JsonValueKind.False"/>, <see cref="bool.FalseString"/> is returned.
/// </para>
///
/// <para>
- /// For <see cref="JsonValueType.String"/>, the value of <see cref="GetString"/>() is returned.
+ /// For <see cref="JsonValueKind.String"/>, the value of <see cref="GetString"/>() is returned.
/// </para>
///
/// <para>
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- private string DebuggerDisplay => $"Type = {Type} : \"{ToString()}\"";
+ private string DebuggerDisplay => $"ValueKind = {ValueKind} : \"{ToString()}\"";
}
}
}
private string DebuggerDisplay
- => Value.Type == JsonValueType.Undefined ? "<Undefined>" : $"\"{ToString()}\"";
+ => Value.ValueKind == JsonValueKind.Undefined ? "<Undefined>" : $"\"{ToString()}\"";
}
}
/// <summary>
/// Specifies the data type of a JSON value.
/// </summary>
- public enum JsonValueType : byte
+ public enum JsonValueKind : byte
{
/// <summary>
/// Indicates that there is no value (as distinct from <see cref="Null"/>).
return (newLines, lastLineFeedIndex);
}
- internal static JsonValueType ToValueType(this JsonTokenType tokenType)
+ internal static JsonValueKind ToValueKind(this JsonTokenType tokenType)
{
switch (tokenType)
{
case JsonTokenType.None:
- return JsonValueType.Undefined;
+ return JsonValueKind.Undefined;
case JsonTokenType.StartArray:
- return JsonValueType.Array;
+ return JsonValueKind.Array;
case JsonTokenType.StartObject:
- return JsonValueType.Object;
+ return JsonValueKind.Object;
case JsonTokenType.String:
case JsonTokenType.Number:
case JsonTokenType.True:
case JsonTokenType.False:
case JsonTokenType.Null:
- return (JsonValueType)((byte)tokenType - 3);
+ return (JsonValueKind)((byte)tokenType - 3);
default:
Debug.Fail($"No mapping for token type {tokenType}");
- return JsonValueType.Undefined;
+ return JsonValueKind.Undefined;
}
}
JsonTokenType actualType)
{
return GetInvalidOperationException(
- SR.Format(SR.JsonElementHasWrongType, expectedType.ToValueType(), actualType.ToValueType()));
+ SR.Format(SR.JsonElementHasWrongType, expectedType.ToValueKind(), actualType.ToValueKind()));
}
[MethodImpl(MethodImplOptions.NoInlining)]
JsonTokenType actualType)
{
return GetInvalidOperationException(
- SR.Format(SR.JsonElementHasWrongType, expectedTypeName, actualType.ToValueType()));
+ SR.Format(SR.JsonElementHasWrongType, expectedTypeName, actualType.ToValueKind()));
}
public static void ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte = default, ReadOnlySpan<byte> bytes = default)
using (JsonDocument doc = JsonDocument.Parse(new MemoryStream(data)))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.Equal(11, root.GetInt32());
}
}
JsonDocument.Parse(new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, data: data)))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.Equal(11, root.GetInt32());
}
}
using (JsonDocument doc = await JsonDocument.ParseAsync(new MemoryStream(data)))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.Equal(11, root.GetInt32());
}
}
new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, data: data)))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.Equal(11, root.GetInt32());
}
}
private static void DepthFirstAppend(StringBuilder buf, JsonElement element)
{
- JsonValueType type = element.Type;
+ JsonValueKind kind = element.ValueKind;
- switch (type)
+ switch (kind)
{
- case JsonValueType.False:
- case JsonValueType.True:
- case JsonValueType.String:
- case JsonValueType.Number:
+ case JsonValueKind.False:
+ case JsonValueKind.True:
+ case JsonValueKind.String:
+ case JsonValueKind.Number:
{
buf.Append(element.ToString());
buf.Append(", ");
break;
}
- case JsonValueType.Object:
+ case JsonValueKind.Object:
{
foreach (JsonProperty prop in element.EnumerateObject())
{
break;
}
- case JsonValueType.Array:
+ case JsonValueKind.Array:
{
foreach (JsonElement child in element.EnumerateArray())
{
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Array, root.Type);
+ Assert.Equal(JsonValueKind.Array, root.ValueKind);
Assert.Equal(SR.ParseJson, root.ToString());
}
}
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Object, root.Type);
+ Assert.Equal(JsonValueKind.Object, root.ValueKind);
Assert.Equal(SR.BasicJson, root.ToString());
}
}
Assert.Equal("425-214-3151", phoneNumber);
Assert.Equal(25, age);
- Assert.Equal(JsonValueType.Null, root[3].Type);
+ Assert.Equal(JsonValueKind.Null, root[3].ValueKind);
Assert.Throws<IndexOutOfRangeException>(() => root[4]);
}
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
DateTime expectedDateTime = DateTime.Parse(expectedString);
DateTimeOffset expectedDateTimeOffset = DateTimeOffset.Parse(expectedString);
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
Assert.True(root.TryGetDateTime(out DateTime DateTimeVal));
Assert.Equal(expectedDateTime, DateTimeVal);
DateTime expectedDateTime = DateTime.ParseExact(expectedString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
DateTimeOffset expectedDateTimeOffset = DateTimeOffset.ParseExact(expectedString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
Assert.True(root.TryGetDateTime(out DateTime DateTimeVal));
Assert.Equal(expectedDateTime, DateTimeVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
Assert.False(root.TryGetDateTime(out DateTime DateTimeVal));
Assert.Equal(default, DateTimeVal);
Guid expected = new Guid(expectedStr);
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
Assert.True(root.TryGetGuid(out Guid GuidVal));
Assert.Equal(expected, GuidVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
Assert.False(root.TryGetGuid(out Guid GuidVal));
Assert.Equal(default, GuidVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
Assert.True(root.TryGetSingle(out float floatVal));
Assert.Equal(expectedFloat, floatVal);
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Number, root.Type);
+ Assert.Equal(JsonValueKind.Number, root.ValueKind);
if (PlatformDetection.IsFullFramework)
{
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Array, root.Type);
+ Assert.Equal(JsonValueKind.Array, root.ValueKind);
Assert.Equal(5, root.GetArrayLength());
for (int i = root.GetArrayLength() - 1; i >= 0; i--)
JsonElement root = doc.RootElement;
doc.Dispose();
- Assert.Throws<ObjectDisposedException>(() => root.Type);
+ Assert.Throws<ObjectDisposedException>(() => root.ValueKind);
Assert.Throws<ObjectDisposedException>(() => root.GetArrayLength());
Assert.Throws<ObjectDisposedException>(() => root.EnumerateArray());
Assert.Throws<ObjectDisposedException>(() => root.EnumerateObject());
{
JsonElement root = default;
- Assert.Equal(JsonValueType.Undefined, root.Type);
+ Assert.Equal(JsonValueKind.Undefined, root.ValueKind);
Assert.Throws<InvalidOperationException>(() => root.GetArrayLength());
Assert.Throws<InvalidOperationException>(() => root.EnumerateArray());
JsonElement root = doc.RootElement;
const string ErrorMessage = "Cannot transcode invalid UTF-8 JSON text to UTF-16 string.";
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
AssertExtensions.Throws<InvalidOperationException>(() => root.GetString(), ErrorMessage);
Assert.Throws<InvalidOperationException>(() => root.GetRawText());
const string DummyString = "dummy-string";
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.String, root.Type);
+ Assert.Equal(JsonValueKind.String, root.ValueKind);
Assert.Throws<FormatException>(() => root.GetBytesFromBase64());
Assert.False(root.TryGetBytesFromBase64(out byte[] value));
Assert.Null(value);
void assertPascal(JsonElement elem)
{
- Assert.Equal(JsonValueType.String, elem.Type);
+ Assert.Equal(JsonValueKind.String, elem.ValueKind);
Assert.Equal("no", elem.GetString());
}
void assertCamel(JsonElement elem)
{
- Assert.Equal(JsonValueType.Number, elem.Type);
+ Assert.Equal(JsonValueKind.Number, elem.ValueKind);
Assert.Equal(42, elem.GetInt32());
}
void assertOdd(JsonElement elem)
{
- Assert.Equal(JsonValueType.False, elem.Type);
+ Assert.Equal(JsonValueKind.False, elem.ValueKind);
Assert.Equal(false, elem.GetBoolean());
}
using (JsonDocument doc = JsonDocument.Parse(okayJson))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Array, root.Type);
+ Assert.Equal(JsonValueKind.Array, root.ValueKind);
JsonElement cur = root;
- while (cur.Type == JsonValueType.Array)
+ while (cur.ValueKind == JsonValueKind.Array)
{
Assert.Equal(1, cur.GetArrayLength());
cur = cur[0];
depth++;
}
- Assert.Equal(JsonValueType.Number, cur.Type);
+ Assert.Equal(JsonValueKind.Number, cur.ValueKind);
Assert.Equal(2, cur.GetInt32());
Assert.Equal(OkayCount, depth);
}
using (JsonDocument doc = JsonDocument.Parse(okayJson, new JsonDocumentOptions { MaxDepth = OkayCount }))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Array, root.Type);
+ Assert.Equal(JsonValueKind.Array, root.ValueKind);
JsonElement cur = root;
- while (cur.Type == JsonValueType.Array)
+ while (cur.ValueKind == JsonValueKind.Array)
{
Assert.Equal(1, cur.GetArrayLength());
cur = cur[0];
depth++;
}
- Assert.Equal(JsonValueType.Number, cur.Type);
+ Assert.Equal(JsonValueKind.Number, cur.ValueKind);
Assert.Equal(2, cur.GetInt32());
Assert.Equal(OkayCount, depth);
}
using (JsonDocument doc = JsonDocument.Parse(okayJson, new JsonDocumentOptions { MaxDepth = MaxDepthOverflow }))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Array, root.Type);
+ Assert.Equal(JsonValueKind.Array, root.ValueKind);
}
using (JsonDocument doc = JsonDocument.Parse(okayJson, new JsonDocumentOptions { MaxDepth = int.MaxValue }))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Array, root.Type);
+ Assert.Equal(JsonValueKind.Array, root.ValueKind);
}
}
using (JsonDocument doc = JsonDocument.Parse("/* some comment */{ }", options))
{
- Assert.Equal(JsonValueType.Object, doc.RootElement.Type);
+ Assert.Equal(JsonValueKind.Object, doc.RootElement.ValueKind);
}
}
JsonElement.ArrayEnumerator enumerator = enumerable.GetEnumerator();
JsonElement.ArrayEnumerator defaultEnumerator = default;
- Assert.Equal(JsonValueType.Undefined, enumerable.Current.Type);
- Assert.Equal(JsonValueType.Undefined, enumerator.Current.Type);
+ Assert.Equal(JsonValueKind.Undefined, enumerable.Current.ValueKind);
+ Assert.Equal(JsonValueKind.Undefined, enumerator.Current.ValueKind);
Assert.False(enumerable.MoveNext());
Assert.False(enumerable.MoveNext());
JsonElement.ObjectEnumerator enumerator = enumerable.GetEnumerator();
JsonElement.ObjectEnumerator defaultEnumerator = default;
- Assert.Equal(JsonValueType.Undefined, enumerable.Current.Value.Type);
- Assert.Equal(JsonValueType.Undefined, enumerator.Current.Value.Type);
+ Assert.Equal(JsonValueKind.Undefined, enumerable.Current.Value.ValueKind);
+ Assert.Equal(JsonValueKind.Undefined, enumerator.Current.Value.ValueKind);
Assert.Throws<InvalidOperationException>(() => enumerable.Current.Name);
Assert.Throws<InvalidOperationException>(() => enumerator.Current.Name);
using (JsonDocument doc = JsonDocument.Parse(json))
{
JsonElement root = doc.RootElement;
- Assert.Equal(JsonValueType.Object, root.Type);
+ Assert.Equal(JsonValueKind.Object, root.ValueKind);
Assert.True(root.GetProperty("first").GetProperty("true").GetBoolean());
Assert.False(root.GetProperty("first").GetProperty("false").GetBoolean());
- Assert.Equal(JsonValueType.Null, root.GetProperty("first").GetProperty("null").Type);
+ Assert.Equal(JsonValueKind.Null, root.GetProperty("first").GetProperty("null").ValueKind);
Assert.Equal(3, root.GetProperty("first").GetProperty("int").GetInt32());
Assert.Equal(3.14159f, root.GetProperty("first").GetProperty("nearlyPi").GetSingle());
Assert.Equal("This is some text that does not end... <EOT>", root.GetProperty("first").GetProperty("text").GetString());
Assert.True(jElement.ValueEquals(default(ReadOnlySpan<char>)));
Assert.True(jElement.ValueEquals((ReadOnlySpan<byte>)null));
Assert.True(jElement.ValueEquals(default(ReadOnlySpan<byte>)));
-
+
Assert.False(jElement.ValueEquals(Array.Empty<byte>()));
Assert.False(jElement.ValueEquals(""));
Assert.False(jElement.ValueEquals("".AsSpan()));
[Fact]
public static void CloneAtInnerNumber()
{
- CloneAtInner("1.21e9", JsonValueType.Number);
+ CloneAtInner("1.21e9", JsonValueKind.Number);
}
[Fact]
public static void CloneAtInnerString()
{
- CloneAtInner("\" this string has \\u0039 spaces\"", JsonValueType.String);
+ CloneAtInner("\" this string has \\u0039 spaces\"", JsonValueKind.String);
}
[Fact]
public static void CloneAtInnerTrue()
{
- CloneAtInner("true", JsonValueType.True);
+ CloneAtInner("true", JsonValueKind.True);
}
[Fact]
public static void CloneAtInnerFalse()
{
- CloneAtInner("false", JsonValueType.False);
+ CloneAtInner("false", JsonValueKind.False);
}
[Fact]
public static void CloneAtInnerNull()
{
- CloneAtInner("null", JsonValueType.Null);
+ CloneAtInner("null", JsonValueKind.Null);
}
[Fact]
}
]
}",
- JsonValueType.Object);
+ JsonValueKind.Object);
}
[Fact]
null
]",
- JsonValueType.Array);
+ JsonValueKind.Array);
}
- private static void CloneAtInner(string innerJson, JsonValueType valueType)
+ private static void CloneAtInner(string innerJson, JsonValueKind valueType)
{
string json = $"{{ \"obj\": [ {{ \"not target\": true, \"target\": {innerJson} }}, 5 ] }}";
using (JsonDocument doc = JsonDocument.Parse(json))
{
JsonElement target = doc.RootElement.GetProperty("obj")[0].GetProperty("target");
- Assert.Equal(valueType, target.Type);
+ Assert.Equal(valueType, target.ValueKind);
clone = target.Clone();
}
Dictionary<string, object> obj = JsonSerializer.Deserialize<Dictionary<string, object>>(@"{""Key1"":1}");
Assert.Equal(1, obj.Count);
JsonElement element = (JsonElement)obj["Key1"];
- Assert.Equal(JsonValueType.Number, element.Type);
+ Assert.Equal(JsonValueKind.Number, element.ValueKind);
Assert.Equal(1, element.GetInt32());
string json = JsonSerializer.Serialize(obj);
IDictionary<string, object> obj = JsonSerializer.Deserialize<IDictionary<string, object>>(@"{""Key1"":1}");
Assert.Equal(1, obj.Count);
JsonElement element = (JsonElement)obj["Key1"];
- Assert.Equal(JsonValueType.Number, element.Type);
+ Assert.Equal(JsonValueKind.Number, element.ValueKind);
Assert.Equal(1, element.GetInt32());
string json = JsonSerializer.Serialize(obj);
// Baseline with missing.
ClassWithExtensionProperty obj = JsonSerializer.Deserialize<ClassWithExtensionProperty>(jsonMissing);
Assert.Equal(1, obj.MyOverflow.Count);
- Assert.Equal(JsonValueType.Null, obj.MyOverflow["MyNestedClassMissing"].Type);
+ Assert.Equal(JsonValueKind.Null, obj.MyOverflow["MyNestedClassMissing"].ValueKind);
}
{
// Currently we do not ignore nulls in the extension data. The JsonDocument would also need to support this mode
// for any lower-level nulls.
Assert.Equal(1, obj.MyOverflow.Count);
- Assert.Equal(JsonValueType.Null, obj.MyOverflow["MyNestedClassMissing"].Type);
+ Assert.Equal(JsonValueKind.Null, obj.MyOverflow["MyNestedClassMissing"].ValueKind);
}
}
Assert.IsType<JsonElement>(roundTripObj.MyOverflow["test2"]);
Assert.IsType<JsonElement>(roundTripObj.MyOverflow["test3"]);
- Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test"]).Type);
+ Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test"]).ValueKind);
- Assert.Equal(JsonValueType.Number, ((JsonElement)roundTripObj.MyOverflow["test1"]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)roundTripObj.MyOverflow["test1"]).ValueKind);
Assert.Equal(1, ((JsonElement)roundTripObj.MyOverflow["test1"]).GetInt32());
Assert.Equal(1, ((JsonElement)roundTripObj.MyOverflow["test1"]).GetInt64());
- Assert.Equal(JsonValueType.String, ((JsonElement)roundTripObj.MyOverflow["test2"]).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)roundTripObj.MyOverflow["test2"]).ValueKind);
Assert.Equal("text", ((JsonElement)roundTripObj.MyOverflow["test2"]).GetString());
- Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test3"]).Type);
+ Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test3"]).ValueKind);
Assert.Equal("ObjectProp", ((JsonElement)roundTripObj.MyOverflow["test3"]).GetProperty("Prop").GetString());
- Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test4"]).Type);
+ Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test4"]).ValueKind);
Assert.Equal("StructProp", ((JsonElement)roundTripObj.MyOverflow["test4"]).GetProperty("Prop").GetString());
- Assert.Equal(JsonValueType.Object, ((JsonElement)roundTripObj.MyOverflow["test5"]).Type);
+ Assert.Equal(JsonValueKind.Object, ((JsonElement)roundTripObj.MyOverflow["test5"]).ValueKind);
Assert.Equal("Value", ((JsonElement)roundTripObj.MyOverflow["test5"]).GetProperty("Key").GetString());
Assert.Equal("Value1", ((JsonElement)roundTripObj.MyOverflow["test5"]).GetProperty("Key1").GetString());
}
public void Verify()
{
- Assert.Equal(JsonValueType.Number, Number.Type);
+ Assert.Equal(JsonValueKind.Number, Number.ValueKind);
Assert.Equal("1", Number.ToString());
- Assert.Equal(JsonValueType.True, True.Type);
+ Assert.Equal(JsonValueKind.True, True.ValueKind);
Assert.Equal("True", True.ToString());
- Assert.Equal(JsonValueType.False, False.Type);
+ Assert.Equal(JsonValueKind.False, False.ValueKind);
Assert.Equal("False", False.ToString());
- Assert.Equal(JsonValueType.String, String.Type);
+ Assert.Equal(JsonValueKind.String, String.ValueKind);
Assert.Equal("Hello", String.ToString());
- Assert.Equal(JsonValueType.Array, Array.Type);
+ Assert.Equal(JsonValueKind.Array, Array.ValueKind);
JsonElement[] elements = Array.EnumerateArray().ToArray();
- Assert.Equal(JsonValueType.Number, elements[0].Type);
+ Assert.Equal(JsonValueKind.Number, elements[0].ValueKind);
Assert.Equal("2", elements[0].ToString());
- Assert.Equal(JsonValueType.False, elements[1].Type);
+ Assert.Equal(JsonValueKind.False, elements[1].ValueKind);
Assert.Equal("False", elements[1].ToString());
- Assert.Equal(JsonValueType.True, elements[2].Type);
+ Assert.Equal(JsonValueKind.True, elements[2].ValueKind);
Assert.Equal("True", elements[2].ToString());
- Assert.Equal(JsonValueType.String, elements[3].Type);
+ Assert.Equal(JsonValueKind.String, elements[3].ValueKind);
Assert.Equal("Goodbye", elements[3].ToString());
- Assert.Equal(JsonValueType.Object, Object.Type);
+ Assert.Equal(JsonValueKind.Object, Object.ValueKind);
Assert.Equal("{}", Object.ToString());
- //Assert.Equal(JsonValueType.Null, Null.Type);
+ //Assert.Equal(JsonValueKind.Null, Null.ValueKind);
//Assert.Equal("Null", Null.ToString());
}
}
public void Verify()
{
- Assert.Equal(JsonValueType.Number, Array[0].Type);
+ Assert.Equal(JsonValueKind.Number, Array[0].ValueKind);
Assert.Equal("1", Array[0].ToString());
- Assert.Equal(JsonValueType.True, Array[1].Type);
+ Assert.Equal(JsonValueKind.True, Array[1].ValueKind);
Assert.Equal("True", Array[1].ToString());
- Assert.Equal(JsonValueType.False, Array[2].Type);
+ Assert.Equal(JsonValueKind.False, Array[2].ValueKind);
Assert.Equal("False", Array[2].ToString());
- Assert.Equal(JsonValueType.String, Array[3].Type);
+ Assert.Equal(JsonValueKind.String, Array[3].ValueKind);
Assert.Equal("Hello", Array[3].ToString());
}
}
object[] array = JsonSerializer.Deserialize<object[]>(@"[[]]");
Assert.Equal(1, array.Length);
Assert.IsType<JsonElement>(array[0]);
- Assert.Equal(JsonValueType.Array, ((JsonElement)array[0]).Type);
+ Assert.Equal(JsonValueKind.Array, ((JsonElement)array[0]).ValueKind);
}
[Fact]
object[] array = JsonSerializer.Deserialize<object[]>(@"[{}]");
Assert.Equal(1, array.Length);
Assert.IsType<JsonElement>(array[0]);
- Assert.Equal(JsonValueType.Object, ((JsonElement)array[0]).Type);
+ Assert.Equal(JsonValueKind.Object, ((JsonElement)array[0]).ValueKind);
// Scenario described in https://github.com/dotnet/corefx/issues/36169
array = JsonSerializer.Deserialize<object[]>("[1, false]");
Assert.Equal(2, array.Length);
Assert.IsType<JsonElement>(array[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)array[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)array[0]).ValueKind);
Assert.Equal(1, ((JsonElement)array[0]).GetInt32());
Assert.IsType<JsonElement>(array[1]);
- Assert.Equal(JsonValueType.False, ((JsonElement)array[1]).Type);
+ Assert.Equal(JsonValueKind.False, ((JsonElement)array[1]).ValueKind);
array = JsonSerializer.Deserialize<object[]>(@"[1, false, { ""name"" : ""Person"" }]");
Assert.Equal(3, array.Length);
Assert.IsType<JsonElement>(array[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)array[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)array[0]).ValueKind);
Assert.Equal(1, ((JsonElement)array[0]).GetInt32());
Assert.IsType<JsonElement>(array[1]);
- Assert.Equal(JsonValueType.False, ((JsonElement)array[1]).Type);
+ Assert.Equal(JsonValueKind.False, ((JsonElement)array[1]).ValueKind);
Assert.IsType<JsonElement>(array[2]);
- Assert.Equal(JsonValueType.Object, ((JsonElement)array[2]).Type);
+ Assert.Equal(JsonValueKind.Object, ((JsonElement)array[2]).ValueKind);
}
[Fact]
object obj = JsonSerializer.Deserialize<object>(@"""hello""");
Assert.IsType<JsonElement>(obj);
JsonElement element = (JsonElement)obj;
- Assert.Equal(JsonValueType.String, element.Type);
+ Assert.Equal(JsonValueKind.String, element.ValueKind);
Assert.Equal("hello", element.GetString());
obj = JsonSerializer.Deserialize<object>(@"true");
element = (JsonElement)obj;
- Assert.Equal(JsonValueType.True, element.Type);
+ Assert.Equal(JsonValueKind.True, element.ValueKind);
Assert.Equal(true, element.GetBoolean());
obj = JsonSerializer.Deserialize<object>(@"null");
obj = JsonSerializer.Deserialize<object>(@"[]");
element = (JsonElement)obj;
- Assert.Equal(JsonValueType.Array, element.Type);
+ Assert.Equal(JsonValueKind.Array, element.ValueKind);
}
[Fact]
object obj = JsonSerializer.Deserialize(bytes, typeof(object));
Assert.IsType<JsonElement>(obj);
JsonElement element = (JsonElement)obj;
- Assert.Equal(JsonValueType.Number, element.Type);
+ Assert.Equal(JsonValueKind.Number, element.ValueKind);
Assert.Equal(42, element.GetInt32());
}
return;
Assert.IsType<JsonElement>(MyInt16[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt16[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt16[0]).ValueKind);
Assert.Equal(1, ((JsonElement)MyInt16[0]).GetInt16());
Assert.IsType<JsonElement>(MyInt32[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt32[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt32[0]).ValueKind);
Assert.Equal(2, ((JsonElement)MyInt32[0]).GetInt32());
Assert.IsType<JsonElement>(MyInt64[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt64[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt64[0]).ValueKind);
Assert.Equal(3L, ((JsonElement)MyInt64[0]).GetInt64());
Assert.IsType<JsonElement>(MyUInt16[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt16[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt16[0]).ValueKind);
Assert.Equal(4u, ((JsonElement)MyUInt16[0]).GetUInt16());
Assert.IsType<JsonElement>(MyUInt32[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt32[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt32[0]).ValueKind);
Assert.Equal(5u, ((JsonElement)MyUInt32[0]).GetUInt32());
Assert.IsType<JsonElement>(MyUInt64[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt64[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt64[0]).ValueKind);
Assert.Equal(6UL, ((JsonElement)MyUInt64[0]).GetUInt64());
Assert.IsType<JsonElement>(MyByte[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyByte[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyByte[0]).ValueKind);
Assert.Equal(7, ((JsonElement)MyByte[0]).GetByte());
Assert.IsType<JsonElement>(MySByte[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MySByte[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MySByte[0]).ValueKind);
Assert.Equal(8, ((JsonElement)MySByte[0]).GetSByte());
Assert.IsType<JsonElement>(MyChar[0]);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyChar[0]).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyChar[0]).ValueKind);
Assert.Equal("a", ((JsonElement)MyChar[0]).GetString());
Assert.IsType<JsonElement>(MyString[0]);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyString[0]).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyString[0]).ValueKind);
Assert.Equal("Hello", ((JsonElement)MyString[0]).GetString());
Assert.IsType<JsonElement>(MyDecimal[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyDecimal[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDecimal[0]).ValueKind);
Assert.Equal(3.3m, ((JsonElement)MyDecimal[0]).GetDecimal());
Assert.IsType<JsonElement>(MyBooleanFalse[0]);
- Assert.Equal(JsonValueType.False, ((JsonElement)MyBooleanFalse[0]).Type);
+ Assert.Equal(JsonValueKind.False, ((JsonElement)MyBooleanFalse[0]).ValueKind);
Assert.Equal(false, ((JsonElement)MyBooleanFalse[0]).GetBoolean());
Assert.IsType<JsonElement>(MyBooleanTrue[0]);
- Assert.Equal(JsonValueType.True, ((JsonElement)MyBooleanTrue[0]).Type);
+ Assert.Equal(JsonValueKind.True, ((JsonElement)MyBooleanTrue[0]).ValueKind);
Assert.Equal(true, ((JsonElement)MyBooleanTrue[0]).GetBoolean());
Assert.IsType<JsonElement>(MySingle[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MySingle[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MySingle[0]).ValueKind);
Assert.Equal(1.1f, ((JsonElement)MySingle[0]).GetSingle());
Assert.IsType<JsonElement>(MyDouble[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyDouble[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDouble[0]).ValueKind);
Assert.Equal(2.2d, ((JsonElement)MyDouble[0]).GetDouble());
Assert.IsType<JsonElement>(MyDateTime[0]);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyDateTime[0]).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyDateTime[0]).ValueKind);
Assert.Equal(new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc), ((JsonElement)MyDateTime[0]).GetDateTime());
Assert.IsType<JsonElement>(MyGuid[0]);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyGuid[0]).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyGuid[0]).ValueKind);
Assert.Equal(new Guid("97E9F02C-337E-4615-B26C-0020F5DC28C9"), ((JsonElement)MyGuid[0]).GetGuid());
Assert.IsType<JsonElement>(MyUri[0]);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyUri[0]).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyUri[0]).ValueKind);
// TODO: Use JsonElement.GetUri() when https://github.com/dotnet/corefx/issues/38647 is implemented.
Assert.Equal(new Uri("https://github.com/dotnet/corefx"), new Uri(((JsonElement)MyUri[0]).GetString()));
Assert.IsType<JsonElement>(MyEnum[0]);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyEnum[0]).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyEnum[0]).ValueKind);
Assert.Equal(SampleEnum.Two, (SampleEnum)((JsonElement)MyEnum[0]).GetUInt32());
}
}
return;
Assert.IsType<JsonElement>(MyInt16);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt16).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt16).ValueKind);
Assert.Equal(1, ((JsonElement)MyInt16).GetInt16());
Assert.IsType<JsonElement>(MyInt32);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt32).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt32).ValueKind);
Assert.Equal(2, ((JsonElement)MyInt32).GetInt32());
Assert.IsType<JsonElement>(MyInt64);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyInt64).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyInt64).ValueKind);
Assert.Equal(3L, ((JsonElement)MyInt64).GetInt64());
Assert.IsType<JsonElement>(MyUInt16);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt16).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt16).ValueKind);
Assert.Equal(4u, ((JsonElement)MyUInt16).GetUInt16());
Assert.IsType<JsonElement>(MyUInt32);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt32).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt32).ValueKind);
Assert.Equal(5u, ((JsonElement)MyUInt32).GetUInt32());
Assert.IsType<JsonElement>(MyUInt64);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyUInt64).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyUInt64).ValueKind);
Assert.Equal(6UL, ((JsonElement)MyUInt64).GetUInt64());
Assert.IsType<JsonElement>(MyByte);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyByte).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyByte).ValueKind);
Assert.Equal(7, ((JsonElement)MyByte).GetByte());
Assert.IsType<JsonElement>(MySByte);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MySByte).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MySByte).ValueKind);
Assert.Equal(8, ((JsonElement)MySByte).GetSByte());
Assert.IsType<JsonElement>(MyChar);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyChar).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyChar).ValueKind);
Assert.Equal("a", ((JsonElement)MyChar).GetString());
Assert.IsType<JsonElement>(MyString);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyString).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyString).ValueKind);
Assert.Equal("Hello", ((JsonElement)MyString).GetString());
Assert.IsType<JsonElement>(MyDecimal);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyDecimal).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDecimal).ValueKind);
Assert.Equal(3.3m, ((JsonElement)MyDecimal).GetDecimal());
Assert.IsType<JsonElement>(MyBooleanFalse);
- Assert.Equal(JsonValueType.False, ((JsonElement)MyBooleanFalse).Type);
+ Assert.Equal(JsonValueKind.False, ((JsonElement)MyBooleanFalse).ValueKind);
Assert.Equal(false, ((JsonElement)MyBooleanFalse).GetBoolean());
Assert.IsType<JsonElement>(MyBooleanTrue);
- Assert.Equal(JsonValueType.True, ((JsonElement)MyBooleanTrue).Type);
+ Assert.Equal(JsonValueKind.True, ((JsonElement)MyBooleanTrue).ValueKind);
Assert.Equal(true, ((JsonElement)MyBooleanTrue).GetBoolean());
Assert.IsType<JsonElement>(MySingle);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MySingle).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MySingle).ValueKind);
Assert.Equal(1.1f, ((JsonElement)MySingle).GetSingle());
Assert.IsType<JsonElement>(MyDouble);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyDouble).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyDouble).ValueKind);
Assert.Equal(2.2d, ((JsonElement)MyDouble).GetDouble());
Assert.IsType<JsonElement>(MyDateTime);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyDateTime).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyDateTime).ValueKind);
Assert.Equal(new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc), ((JsonElement)MyDateTime).GetDateTime());
Assert.IsType<JsonElement>(MyGuid);
- Assert.Equal(JsonValueType.String, ((JsonElement)MyGuid).Type);
+ Assert.Equal(JsonValueKind.String, ((JsonElement)MyGuid).ValueKind);
Assert.Equal(new Guid("5BB9D872-DA8A-471E-AA70-08E19102683D"), ((JsonElement)MyGuid).GetGuid());
Assert.IsType<JsonElement>(MyEnum);
- Assert.Equal(JsonValueType.Number, ((JsonElement)MyEnum).Type);
+ Assert.Equal(JsonValueKind.Number, ((JsonElement)MyEnum).ValueKind);
Assert.Equal(SampleEnum.Two, (SampleEnum)((JsonElement)MyEnum).GetUInt32());
Assert.Equal(1, ((JsonElement)MyStruct).GetProperty("One").GetInt32());
Assert.Equal(3.14, ((JsonElement)MyStruct).GetProperty("Two").GetDouble());
ValidateArray((JsonElement)Array);
Assert.IsType<JsonElement>(Object);
JsonElement jsonObject = (JsonElement)Object;
- Assert.Equal(JsonValueType.Object, jsonObject.Type);
+ Assert.Equal(JsonValueKind.Object, jsonObject.ValueKind);
JsonElement.ObjectEnumerator enumerator = jsonObject.EnumerateObject();
JsonProperty property = enumerator.First();
Assert.Equal("NestedArray", property.Name);
void ValidateArray(JsonElement element)
{
- Assert.Equal(JsonValueType.Array, element.Type);
+ Assert.Equal(JsonValueKind.Array, element.ValueKind);
JsonElement[] elements = element.EnumerateArray().ToArray();
- Assert.Equal(JsonValueType.Number, elements[0].Type);
+ Assert.Equal(JsonValueKind.Number, elements[0].ValueKind);
Assert.Equal("1", elements[0].ToString());
- Assert.Equal(JsonValueType.String, elements[1].Type);
+ Assert.Equal(JsonValueKind.String, elements[1].ValueKind);
Assert.Equal("Hello", elements[1].ToString());
- Assert.Equal(JsonValueType.True, elements[2].Type);
+ Assert.Equal(JsonValueKind.True, elements[2].ValueKind);
Assert.Equal(true, elements[2].GetBoolean());
- Assert.Equal(JsonValueType.False, elements[3].Type);
+ Assert.Equal(JsonValueKind.False, elements[3].ValueKind);
Assert.Equal(false, elements[3].GetBoolean());
}