{
private const int UnseekableStreamInitialRentSize = 4096;
+ /// <summary>
+ /// Parse memory as UTF-8-encoded text representing a single JSON value into a JsonDocument.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The <see cref="ReadOnlyMemory{T}"/> value will be used for the entire lifetime of the
+ /// JsonDocument object, and the caller must ensure that the data therein does not change during
+ /// the object lifetime.
+ /// </para>
+ ///
+ /// <para>
+ /// Because the input is considered to be text, a UTF-8 Byte-Order-Mark (BOM) must not be present.
+ /// </para>
+ /// </remarks>
+ /// <param name="utf8Json">JSON text to parse.</param>
+ /// <param name="readerOptions">Options to control the reader behavior during parsing.</param>
+ /// <returns>
+ /// A JsonDocument representation of the JSON value.
+ /// </returns>
+ /// <exception cref="JsonReaderException">
+ /// <paramref name="utf8Json"/> does not represent a valid single JSON value.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="readerOptions"/> contains unsupported options.
+ /// </exception>
public static JsonDocument Parse(ReadOnlyMemory<byte> utf8Json, JsonReaderOptions readerOptions = default)
{
CheckSupportedOptions(readerOptions);
return Parse(utf8Json, readerOptions, null);
}
+ /// <summary>
+ /// Parse a sequence as UTF-8-encoded text representing a single JSON value into a JsonDocument.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The <see cref="ReadOnlySequence{T}"/> may be used for the entire lifetime of the
+ /// JsonDocument object, and the caller must ensure that the data therein does not change during
+ /// the object lifetime.
+ /// </para>
+ ///
+ /// <para>
+ /// Because the input is considered to be text, a UTF-8 Byte-Order-Mark (BOM) must not be present.
+ /// </para>
+ /// </remarks>
+ /// <param name="utf8Json">JSON text to parse.</param>
+ /// <param name="readerOptions">Options to control the reader behavior during parsing.</param>
+ /// <returns>
+ /// A JsonDocument representation of the JSON value.
+ /// </returns>
+ /// <exception cref="JsonReaderException">
+ /// <paramref name="utf8Json"/> does not represent a valid single JSON value.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="readerOptions"/> contains unsupported options.
+ /// </exception>
public static JsonDocument Parse(ReadOnlySequence<byte> utf8Json, JsonReaderOptions readerOptions = default)
{
CheckSupportedOptions(readerOptions);
}
}
+ /// <summary>
+ /// Parse a <see cref="Stream"/> as UTF-8-encoded data representing a single JSON value into a
+ /// JsonDocument. The Stream will be read to completion.
+ /// </summary>
+ /// <param name="utf8Json">JSON data to parse.</param>
+ /// <param name="readerOptions">Options to control the reader behavior during parsing.</param>
+ /// <returns>
+ /// A JsonDocument representation of the JSON value.
+ /// </returns>
+ /// <exception cref="JsonReaderException">
+ /// <paramref name="utf8Json"/> does not represent a valid single JSON value.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="readerOptions"/> contains unsupported options.
+ /// </exception>
public static JsonDocument Parse(Stream utf8Json, JsonReaderOptions readerOptions = default)
{
if (utf8Json == null)
}
}
+ /// <summary>
+ /// Parse a <see cref="Stream"/> as UTF-8-encoded data representing a single JSON value into a
+ /// JsonDocument. The Stream will be read to completion.
+ /// </summary>
+ /// <param name="utf8Json">JSON data to parse.</param>
+ /// <param name="readerOptions">Options to control the reader behavior during parsing.</param>
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
+ /// <returns>
+ /// A Task to produce a JsonDocument representation of the JSON value.
+ /// </returns>
+ /// <exception cref="JsonReaderException">
+ /// <paramref name="utf8Json"/> does not represent a valid single JSON value.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="readerOptions"/> contains unsupported options.
+ /// </exception>
public static Task<JsonDocument> ParseAsync(
Stream utf8Json,
JsonReaderOptions readerOptions = default,
}
}
+ /// <summary>
+ /// Parse text representing a single JSON value into a JsonDocument.
+ /// </summary>
+ /// <remarks>
+ /// The <see cref="ReadOnlyMemory{T}"/> value may be used for the entire lifetime of the
+ /// JsonDocument object, and the caller must ensure that the data therein does not change during
+ /// the object lifetime.
+ /// </remarks>
+ /// <param name="json">JSON text to parse.</param>
+ /// <param name="readerOptions">Options to control the reader behavior during parsing.</param>
+ /// <returns>
+ /// A JsonDocument representation of the JSON value.
+ /// </returns>
+ /// <exception cref="JsonReaderException">
+ /// <paramref name="json"/> does not represent a valid single JSON value.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="readerOptions"/> contains unsupported options.
+ /// </exception>
public static JsonDocument Parse(ReadOnlyMemory<char> json, JsonReaderOptions readerOptions = default)
{
CheckSupportedOptions(readerOptions);
}
}
+ /// <summary>
+ /// Parse text representing a single JSON value into a JsonDocument.
+ /// </summary>
+ /// <param name="json">JSON text to parse.</param>
+ /// <param name="readerOptions">Options to control the reader behavior during parsing.</param>
+ /// <returns>
+ /// A JsonDocument representation of the JSON value.
+ /// </returns>
+ /// <exception cref="JsonReaderException">
+ /// <paramref name="json"/> does not represent a valid single JSON value.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// <paramref name="readerOptions"/> contains unsupported options.
+ /// </exception>
public static JsonDocument Parse(string json, JsonReaderOptions readerOptions = default)
{
if (json == null)
namespace System.Text.Json
{
+ /// <summary>
+ /// Represents a specific JSON value within a <see cref="JsonDocument"/>.
+ /// </summary>
public readonly partial struct JsonElement
{
private readonly JsonDocument _parent;
private readonly int _idx;
+ /// <summary>
+ /// This is an implementation detail and MUST NOT be called by source-package consumers.
+ /// </summary>
internal JsonElement(JsonDocument parent, int idx)
{
// parent is usually not null, but the Current property
_idx = idx;
}
- internal JsonTokenType TokenType => _parent?.GetJsonTokenType(_idx) ?? JsonTokenType.None;
+ private JsonTokenType TokenType => _parent?.GetJsonTokenType(_idx) ?? JsonTokenType.None;
+ /// <summary>
+ /// The <see cref="JsonValueType"/> that the value is.
+ /// </summary>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public JsonValueType Type => TokenType.ToValueType();
+ /// <summary>
+ /// Get the value at a specified index when the current value is a
+ /// <see cref="JsonValueType.Array"/>.
+ /// </summary>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Array"/>.
+ /// </exception>
+ /// <exception cref="IndexOutOfRangeException">
+ /// <paramref name="index"/> is not in the range [0, <see cref="GetArrayLength"/>()).
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public JsonElement this[int index]
{
get
}
}
+ /// <summary>
+ /// Get the number of values contained within the current array value.
+ /// </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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public int GetArrayLength()
{
CheckValidInstance();
return _parent.GetArrayLength(_idx);
}
+ /// <summary>
+ /// Gets a <see cref="JsonElement"/> representing the value of a required property identified
+ /// by <paramref name="propertyName"/>.
+ /// </summary>
+ /// <remarks>
+ /// Property name matching is performed as an ordinal, case-sensitive, comparison.
+ ///
+ /// If a property is defined multiple times for the same object, the last such definition is
+ /// what is matched.
+ /// </remarks>
+ /// <param name="propertyName">Name of the property whose value to return.</param>
+ /// <returns>
+ /// A <see cref="JsonElement"/> representing the value of the requested property.
+ /// </returns>
+ /// <seealso cref="EnumerateObject"/>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// </exception>
+ /// <exception cref="KeyNotFoundException">
+ /// No property was found with the requested name.
+ /// </exception>
+ /// <exception cref="ArgumentNullException">
+ /// <paramref name="propertyName"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public JsonElement GetProperty(string propertyName)
{
if (propertyName == null)
throw new KeyNotFoundException();
}
+ /// <summary>
+ /// Gets a <see cref="JsonElement"/> representing the value of a required property identified
+ /// by <paramref name="propertyName"/>.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Property name matching is performed as an ordinal, case-sensitive, comparison.
+ /// </para>
+ ///
+ /// <para>
+ /// If a property is defined multiple times for the same object, the last such definition is
+ /// what is matched.
+ /// </para>
+ /// </remarks>
+ /// <param name="propertyName">Name of the property whose value to return.</param>
+ /// <returns>
+ /// A <see cref="JsonElement"/> representing the value of the requested property.
+ /// </returns>
+ /// <seealso cref="EnumerateObject"/>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// </exception>
+ /// <exception cref="KeyNotFoundException">
+ /// No property was found with the requested name.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public JsonElement GetProperty(ReadOnlySpan<char> propertyName)
{
if (TryGetProperty(propertyName, out JsonElement property))
throw new KeyNotFoundException();
}
+ /// <summary>
+ /// Gets a <see cref="JsonElement"/> representing the value of a required property identified
+ /// by <paramref name="utf8PropertyName"/>.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Property name matching is performed as an ordinal, case-sensitive, comparison.
+ /// </para>
+ ///
+ /// <para>
+ /// If a property is defined multiple times for the same object, the last such definition is
+ /// what is matched.
+ /// </para>
+ /// </remarks>
+ /// <param name="utf8PropertyName">
+ /// The UTF-8 (with no Byte-Order-Mark (BOM)) representation of the name of the property to return.
+ /// </param>
+ /// <returns>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="KeyNotFoundException">
+ /// No property was found with the requested name.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
+ /// <seealso cref="EnumerateObject"/>
public JsonElement GetProperty(ReadOnlySpan<byte> utf8PropertyName)
{
if (TryGetProperty(utf8PropertyName, out JsonElement property))
throw new KeyNotFoundException();
}
+ /// <summary>
+ /// Looks for a property named <paramref name="propertyName"/> in the current object, returning
+ /// whether or not such a property existed. When the property exists <paramref name="value"/>
+ /// is assigned to the value of that property.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Property name matching is performed as an ordinal, case-sensitive, comparison.
+ /// </para>
+ ///
+ /// <para>
+ /// If a property is defined multiple times for the same object, the last such definition is
+ /// what is matched.
+ /// </para>
+ /// </remarks>
+ /// <param name="propertyName">Name of the property to find.</param>
+ /// <param name="value">Receives the value of the located property.</param>
+ /// <returns>
+ /// <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"/>.
+ /// </exception>
+ /// <exception cref="ArgumentNullException">
+ /// <paramref name="propertyName"/> is <see langword="null"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
+ /// <seealso cref="EnumerateObject"/>
public bool TryGetProperty(string propertyName, out JsonElement value)
{
if (propertyName == null)
return TryGetProperty(propertyName.AsSpan(), out value);
}
+ /// <summary>
+ /// Looks for a property named <paramref name="propertyName"/> in the current object, returning
+ /// whether or not such a property existed. When the property exists <paramref name="value"/>
+ /// is assigned to the value of that property.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Property name matching is performed as an ordinal, case-sensitive, comparison.
+ /// </para>
+ ///
+ /// <para>
+ /// If a property is defined multiple times for the same object, the last such definition is
+ /// what is matched.
+ /// </para>
+ /// </remarks>
+ /// <param name="propertyName">Name of the property to find.</param>
+ /// <param name="value">Receives the value of the located property.</param>
+ /// <returns>
+ /// <see langword="true"/> if the property was found, <see langword="false"/> otherwise.
+ /// </returns>
+ /// <seealso cref="EnumerateObject"/>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool TryGetProperty(ReadOnlySpan<char> propertyName, out JsonElement value)
{
CheckValidInstance();
return _parent.TryGetNamedPropertyValue(_idx, propertyName, out value);
}
+ /// <summary>
+ /// Looks for a property named <paramref name="utf8PropertyName"/> in the current object, returning
+ /// whether or not such a property existed. When the property exists <paramref name="value"/>
+ /// is assigned to the value of that property.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Property name matching is performed as an ordinal, case-sensitive, comparison.
+ /// </para>
+ ///
+ /// <para>
+ /// If a property is defined multiple times for the same object, the last such definition is
+ /// what is matched.
+ /// </para>
+ /// </remarks>
+ /// <param name="utf8PropertyName">
+ /// The UTF-8 (with no Byte-Order-Mark (BOM)) representation of the name of the property to return.
+ /// </param>
+ /// <param name="value">Receives the value of the located property.</param>
+ /// <returns>
+ /// <see langword="true"/> if the property was found, <see langword="false"/> otherwise.
+ /// </returns>
+ /// <seealso cref="EnumerateObject"/>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Object"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool TryGetProperty(ReadOnlySpan<byte> utf8PropertyName, out JsonElement value)
{
CheckValidInstance();
return _parent.TryGetNamedPropertyValue(_idx, utf8PropertyName, out value);
}
+ /// <summary>
+ /// Gets the value of the element as a <see cref="bool"/>.
+ /// </summary>
+ /// <remarks>
+ /// This method does not parse the contents of a JSON string value.
+ /// </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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool GetBoolean()
{
// CheckValidInstance is redundant. Asking for the type will
throw ThrowHelper.GetJsonElementWrongTypeException(nameof(Boolean), type);
}
+ /// <summary>
+ /// Gets the value of the element as a <see cref="string"/>.
+ /// </summary>
+ /// <remarks>
+ /// This method does not create a string representation of values other than JSON strings.
+ /// </remarks>
+ /// <returns>The value of the element as a <see cref="bool"/>.</returns>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.String"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
+ /// <seealso cref="ToString"/>
public string GetString()
{
CheckValidInstance();
return _parent.GetString(_idx, JsonTokenType.String);
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as an <see cref="int"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// This method does not parse the contents of a JSON string value.
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool TryGetInt32(out int value)
{
CheckValidInstance();
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as an <see cref="int"/>.
+ /// </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"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as an <see cref="int"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public int GetInt32()
{
if (TryGetInt32(out int value))
throw new FormatException();
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as a <see cref="uint"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// This method does not parse the contents of a JSON string value.
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
[CLSCompliant(false)]
public bool TryGetUInt32(out uint value)
{
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as a <see cref="uint"/>.
+ /// </summary>
+ /// <returns>The current JSON number as a <see cref="uint"/>.</returns>
+ /// <remarks>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as a <see cref="uint"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
[CLSCompliant(false)]
public uint GetUInt32()
{
throw new FormatException();
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as a <see cref="long"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// This method does not parse the contents of a JSON string value.
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool TryGetInt64(out long value)
{
CheckValidInstance();
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as a <see cref="long"/>.
+ /// </summary>
+ /// <returns>The current JSON number as a <see cref="long"/>.</returns>
+ /// <remarks>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as a <see cref="long"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public long GetInt64()
{
if (TryGetInt64(out long value))
throw new FormatException();
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as a <see cref="ulong"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// This method does not parse the contents of a JSON string value.
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
[CLSCompliant(false)]
public bool TryGetUInt64(out ulong value)
{
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as a <see cref="ulong"/>.
+ /// </summary>
+ /// <returns>The current JSON number as a <see cref="ulong"/>.</returns>
+ /// <remarks>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as a <see cref="ulong"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
[CLSCompliant(false)]
public ulong GetUInt64()
{
throw new FormatException();
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as a <see cref="double"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// <para>
+ /// This method does not parse the contents of a JSON string value.
+ /// </para>
+ ///
+ /// <para>
+ /// On .NET Core this method does not return <see langword="false"/> for values larger than
+ /// <see cref="double.MaxValue"/> (or smaller than <see cref="double.MinValue"/>),
+ /// instead <see langword="true"/> is returned and <see cref="double.PositiveInfinity"/> (or
+ /// <see cref="double.NegativeInfinity"/>) is emitted.
+ /// </para>
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool TryGetDouble(out double value)
{
CheckValidInstance();
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as a <see cref="double"/>.
+ /// </summary>
+ /// <returns>The current JSON number as a <see cref="double"/>.</returns>
+ /// <remarks>
+ /// <para>
+ /// This method does not parse the contents of a JSON string value.
+ /// </para>
+ ///
+ /// <para>
+ /// On .NET Core this method returns <see cref="double.PositiveInfinity"/> (or
+ /// <see cref="double.NegativeInfinity"/>) for values larger than
+ /// <see cref="double.MaxValue"/> (or smaller than <see cref="double.MinValue"/>).
+ /// </para>
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as a <see cref="double"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public double GetDouble()
{
if (TryGetDouble(out double value))
throw new FormatException();
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as a <see cref="float"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// <para>
+ /// This method does not parse the contents of a JSON string value.
+ /// </para>
+ ///
+ /// <para>
+ /// On .NET Core this method does not return <see langword="false"/> for values larger than
+ /// <see cref="float.MaxValue"/> (or smaller than <see cref="float.MinValue"/>),
+ /// instead <see langword="true"/> is returned and <see cref="float.PositiveInfinity"/> (or
+ /// <see cref="float.NegativeInfinity"/>) is emitted.
+ /// </para>
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public bool TryGetSingle(out float value)
{
CheckValidInstance();
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as a <see cref="float"/>.
+ /// </summary>
+ /// <returns>The current JSON number as a <see cref="float"/>.</returns>
+ /// <remarks>
+ /// <para>
+ /// This method does not parse the contents of a JSON string value.
+ /// </para>
+ ///
+ /// <para>
+ /// On .NET Core this method returns <see cref="float.PositiveInfinity"/> (or
+ /// <see cref="float.NegativeInfinity"/>) for values larger than
+ /// <see cref="float.MaxValue"/> (or smaller than <see cref="float.MinValue"/>).
+ /// </para>
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">
+ /// This value's <see cref="Type"/> is not <see cref="JsonValueType.Number"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as a <see cref="float"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public float GetSingle()
{
if (TryGetSingle(out float value))
throw new FormatException();
}
+ /// <summary>
+ /// Attempts to represent the current JSON number as a <see cref="decimal"/>.
+ /// </summary>
+ /// <param name="value">Receives the value.</param>
+ /// <remarks>
+ /// This method does not parse the contents of a JSON string value.
+ /// </remarks>
+ /// <returns>
+ /// <see langword="true"/> if the number can 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.Number"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
+ /// <seealso cref="GetRawText"/>
public bool TryGetDecimal(out decimal value)
{
CheckValidInstance();
return _parent.TryGetValue(_idx, out value);
}
+ /// <summary>
+ /// Gets the current JSON number as a <see cref="decimal"/>.
+ /// </summary>
+ /// <returns>The current JSON number as a <see cref="decimal"/>.</returns>
+ /// <remarks>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="FormatException">
+ /// The value cannot be represented as a <see cref="decimal"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
+ /// <seealso cref="GetRawText"/>
public decimal GetDecimal()
{
if (TryGetDecimal(out decimal value))
throw new FormatException();
}
+ /// <summary>
+ /// This is an implementation detail and MUST NOT be called by source-package consumers.
+ /// </summary>
internal string GetPropertyName()
{
CheckValidInstance();
return _parent.GetNameOfPropertyValue(_idx);
}
+ /// <summary>
+ /// Gets the original input data backing this value, returning it as a <see cref="string"/>.
+ /// </summary>
+ /// <returns>
+ /// The original input data backing this value, returning it as a <see cref="string"/>.
+ /// </returns>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public string GetRawText()
{
CheckValidInstance();
return _parent.GetRawValueAsString(_idx);
}
+ /// <summary>
+ /// This is an implementation detail and MUST NOT be called by source-package consumers.
+ /// </summary>
internal string GetPropertyRawText()
{
CheckValidInstance();
return _parent.GetPropertyRawValueAsString(_idx);
}
+ /// <summary>
+ /// Get an enumerator to enumerate the values in the JSON array represented by this JsonElement.
+ /// </summary>
+ /// <returns>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public ArrayEnumerator EnumerateArray()
{
CheckValidInstance();
return new ArrayEnumerator(this);
}
+ /// <summary>
+ /// Get an enumerator to enumerate the properties in the JSON object represented by this JsonElement.
+ /// </summary>
+ /// <returns>
+ /// 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"/>.
+ /// </exception>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public ObjectEnumerator EnumerateObject()
{
CheckValidInstance();
return new ObjectEnumerator(this);
}
+ /// <summary>
+ /// Gets a string representation for the current value appropriate to the value type.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// For <see cref="JsonValueType.Null"/>, <see cref="string.Empty"/> is returned.
+ /// </para>
+ ///
+ /// <para>
+ /// For <see cref="JsonValueType.True"/>, <see cref="bool.TrueString"/> is returned.
+ /// </para>
+ ///
+ /// <para>
+ /// For <see cref="JsonValueType.False"/>, <see cref="bool.FalseString"/> is returned.
+ /// </para>
+ ///
+ /// <para>
+ /// For <see cref="JsonValueType.String"/>, the value of <see cref="GetString"/>() is returned.
+ /// </para>
+ ///
+ /// <para>
+ /// For other types, the value of <see cref="GetRawText"/>() is returned.
+ /// </para>
+ /// </remarks>
+ /// <returns>
+ /// A string representation for the current value appropriate to the value type.
+ /// </returns>
+ /// <exception cref="ObjectDisposedException">
+ /// The parent <see cref="JsonDocument"/> has been disposed.
+ /// </exception>
public override string ToString()
{
switch (TokenType)