/// <summary> /// Writes the property name and 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="utf8FormattedNumber">The value to be written as a JSON number as part of the name/value pair.</param> /// <exception cref="ArgumentException"> /// Thrown when the specified property name is too large. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when <paramref name="utf8FormattedNumber"/> does not represent a valid JSON number. /// </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="long"/> using the default <see cref="StandardFormat"/> (i.e. 'G'), for example: 32767. /// </remarks> internal void WriteNumber(ReadOnlySpan <byte> utf8PropertyName, ReadOnlySpan <byte> utf8FormattedNumber) { JsonWriterHelper.ValidateProperty(utf8PropertyName); JsonWriterHelper.ValidateNumber(utf8FormattedNumber); WriteNumberEscape(utf8PropertyName, utf8FormattedNumber); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
internal void WriteNumber(JsonEncodedText propertyName, ReadOnlySpan <byte> utf8FormattedNumber) { JsonWriterHelper.ValidateValue(utf8FormattedNumber); JsonWriterHelper.ValidateNumber(utf8FormattedNumber); WriteNumberByOptions(propertyName.EncodedUtf8Bytes, utf8FormattedNumber); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the value (as a JSON number) as an element of a JSON array. /// </summary> /// <param name="utf8FormattedNumber">The value to be written as a JSON number as an element of a JSON array.</param> /// <exception cref="ArgumentException"> /// Thrown when <paramref name="utf8FormattedNumber"/> does not represent a valid JSON number. /// </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="int"/> using the default <see cref="StandardFormat"/> (i.e. 'G'), for example: 32767. /// </remarks> internal void WriteNumberValue(ReadOnlySpan <byte> utf8FormattedNumber) { JsonWriterHelper.ValidateNumber(utf8FormattedNumber); ValidateWritingValue(); if (_writerOptions.Indented) { WriteNumberValueIndented(utf8FormattedNumber); } else { WriteNumberValueMinimized(utf8FormattedNumber); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }