/// <summary> /// Writes the property name and <see cref="float"/> value (as a JSON number) as part of a name/value pair of a JSON object. /// </summary> /// <param name="propertyName">The UTF-16 encoded property name of the JSON object to be transcoded and written as UTF-8.</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="float"/> using the default <see cref="StandardFormat"/> (i.e. 'G'). /// </remarks> public void WriteNumber(ReadOnlySpan <char> propertyName, float value) { JsonWriterHelper.ValidateProperty(propertyName); JsonWriterHelper.ValidateSingle(value); WriteNumberEscape(propertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
private void WriteNumberHelper(ReadOnlySpan <byte> utf8PropertyName, float value) { Debug.Assert(utf8PropertyName.Length <= JsonConstants.MaxTokenSize); JsonWriterHelper.ValidateSingle(value); WriteNumberByOptions(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the pre-encoded property name and <see cref="float"/> 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="float"/> using the default <see cref="StandardFormat"/> (that is, 'G'). /// </remarks> public void WriteNumber(JsonEncodedText propertyName, float value) { ReadOnlySpan <byte> utf8PropertyName = propertyName.EncodedUtf8Bytes; Debug.Assert(utf8PropertyName.Length <= JsonConstants.MaxUnescapedTokenSize); JsonWriterHelper.ValidateSingle(value); WriteNumberByOptions(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the <see cref="float"/> value (as a JSON number) as an element of a JSON array. /// </summary> /// <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="float"/> using the default <see cref="StandardFormat"/> on .NET Core 3 or higher /// and 'G9' on any other framework. /// </remarks> public void WriteNumberValue(float value) { JsonWriterHelper.ValidateSingle(value); ValidateWritingValue(); if (_options.Indented) { WriteNumberValueIndented(value); } else { WriteNumberValueMinimized(value); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the property name and <see cref="float"/> 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="float"/> using the default <see cref="StandardFormat"/> (i.e. 'G'). /// </remarks> public void WriteNumber(ReadOnlySpan <byte> utf8PropertyName, float value, bool escape = true) { JsonWriterHelper.ValidateProperty(utf8PropertyName); JsonWriterHelper.ValidateSingle(value); if (escape) { WriteNumberEscape(utf8PropertyName, value); } else { WriteNumberByOptions(utf8PropertyName, value); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }