/// <summary> /// Writes the property name and <see cref="double"/> value (as a JSON number) as part of a name/value pair of a JSON object. /// </summary> /// <param name="utf8PropertyName">The UTF-8 encoded property name of the JSON object to be written.</param> /// <param name="value">The value to be written as a JSON number as part of the name/value pair.</param> /// <remarks> /// The property name is escaped before writing. /// </remarks> /// <exception cref="ArgumentException"> /// Thrown when the specified property name is too large. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in an invalid JSON to be written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="double"/> using the default <see cref="StandardFormat"/> (i.e. 'G'). /// </remarks> public void WriteNumber(ReadOnlySpan <byte> utf8PropertyName, double value) { JsonWriterHelper.ValidateProperty(utf8PropertyName); JsonWriterHelper.ValidateDouble(value); WriteNumberEscape(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
private void WriteNumberHelper(ReadOnlySpan <byte> utf8PropertyName, double value) { Debug.Assert(utf8PropertyName.Length <= JsonConstants.MaxTokenSize); JsonWriterHelper.ValidateDouble(value); WriteNumberByOptions(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the pre-encoded property name and <see cref="double"/> value (as a JSON number) as part of a name/value pair of a JSON object. /// </summary> /// <param name="propertyName">The JSON-encoded name of the property to write.</param> /// <param name="value">The value to write.</param> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in invalid JSON being written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="double"/> using the default <see cref="StandardFormat"/> (that is, 'G'). /// </remarks> public void WriteNumber(JsonEncodedText propertyName, double value) { ReadOnlySpan<byte> utf8PropertyName = propertyName.EncodedUtf8Bytes; Debug.Assert(utf8PropertyName.Length <= JsonConstants.MaxUnescapedTokenSize); JsonWriterHelper.ValidateDouble(value); WriteNumberByOptions(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the <see cref="double"/> value (as a JSON number) as an element of a JSON array. /// </summary> /// <param name="value">The value to be written as a JSON number as an element of a JSON array.</param> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in an invalid JSON to be written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="double"/> using the default <see cref="StandardFormat"/> (i.e. 'G'). /// </remarks> public void WriteNumberValue(double value) { JsonWriterHelper.ValidateDouble(value); ValidateWritingValue(); if (_writerOptions.Indented) { WriteNumberValueIndented(value); } else { WriteNumberValueMinimized(value); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the property name and <see cref="double"/> value (as a JSON number) as part of a name/value pair of a JSON object. /// </summary> /// <param name="utf8PropertyName">The UTF-8 encoded property name of the JSON object to be written.</param> /// <param name="value">The value to be written as a JSON number as part of the name/value pair.</param> /// <param name="escape">If this is set to false, the writer assumes the property name is properly escaped and skips the escaping step.</param> /// <exception cref="ArgumentException"> /// Thrown when the specified property name is too large. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in an invalid JSON to be written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="double"/> using the default <see cref="StandardFormat"/> (i.e. 'G'). /// </remarks> public void WriteNumber(ReadOnlySpan <byte> utf8PropertyName, double value, bool escape = true) { JsonWriterHelper.ValidateProperty(utf8PropertyName); JsonWriterHelper.ValidateDouble(value); if (escape) { WriteNumberEscape(utf8PropertyName, value); } else { WriteNumberByOptions(utf8PropertyName, value); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }