/// <summary> /// Writes the property name and <see cref="Guid"/> value (as a JSON string) as part of a name/value pair of a JSON object. /// </summary> /// <param name="propertyName">The name of the property to write.</param> /// <param name="value">The value to write.</param> /// <exception cref="ArgumentException"> /// Thrown when the specified property name is too large. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in invalid JSON being written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="Guid"/> using the default <see cref="StandardFormat"/> (that is, 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn. /// The property name is escaped before writing. /// </remarks> public void WriteString(ReadOnlySpan <char> propertyName, Guid value) { JsonWriterHelper.ValidateProperty(propertyName); WriteStringEscape(propertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.String; }
/// <summary> /// Writes the property name and <see cref="DateTimeOffset"/> value (as a JSON string) 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 to write.</param> /// <exception cref="ArgumentException"> /// Thrown when the specified property name is too large. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in invalid JSON being written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="DateTimeOffset"/> using the round-trippable ('O') <see cref="StandardFormat"/> , for example: 2017-06-12T05:30:45.7680000-07:00. /// The property name is escaped before writing. /// </remarks> public void WriteString(ReadOnlySpan <byte> utf8PropertyName, DateTimeOffset value) { JsonWriterHelper.ValidateProperty(utf8PropertyName); WriteStringEscape(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.String; }
public void WriteNumber(ReadOnlySpan <byte> utf8PropertyName, ulong value) { JsonWriterHelper.ValidateProperty(utf8PropertyName); WriteNumberEscape(utf8PropertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <summary> /// Writes the property name and <see cref="decimal"/> value (as a JSON number) as part of a name/value pair of a JSON object. /// </summary> /// <param name="propertyName">The name of the property to write.</param> /// <param name="value">The value to write.</param> /// <exception cref="ArgumentException"> /// Thrown when the specified property name is too large. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in invalid JSON being written (while validation is enabled). /// </exception> /// <remarks> /// Writes the <see cref="decimal"/> using the default <see cref="StandardFormat"/> (that is, 'G'). /// The property name is escaped before writing. /// </remarks> public void WriteNumber(ReadOnlySpan <char> propertyName, decimal value) { JsonWriterHelper.ValidateProperty(propertyName); WriteNumberEscape(propertyName, value); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Number; }
/// <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; }
/// <summary> /// Writes the property name and the JSON literal "null" 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> /// <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> public void WriteNull(ReadOnlySpan <byte> utf8PropertyName) { JsonWriterHelper.ValidateProperty(utf8PropertyName); ReadOnlySpan <byte> span = JsonConstants.NullValue; WriteLiteralEscape(utf8PropertyName, span); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Null; }
/// <summary> /// Writes the property name and <see cref="bool"/> value (as a JSON literal "true" or "false") 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 literal "true" or "false" 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> public void WriteBoolean(ReadOnlySpan <byte> utf8PropertyName, bool value) { JsonWriterHelper.ValidateProperty(utf8PropertyName); ReadOnlySpan <byte> span = value ? JsonConstants.TrueValue : JsonConstants.FalseValue; WriteLiteralEscape(utf8PropertyName, span); SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = value ? JsonTokenType.True : JsonTokenType.False; }
/// <summary> /// Writes the property name and <see cref="Guid"/> value (as a JSON string) 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 string 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="Guid"/> using the default <see cref="StandardFormat"/> (i.e. 'D'), as the form: nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn. /// </remarks> public void WriteString(ReadOnlySpan <byte> utf8PropertyName, Guid value, bool escape = true) { JsonWriterHelper.ValidateProperty(utf8PropertyName); if (escape) { WriteStringEscape(utf8PropertyName, value); } else { WriteStringByOptions(utf8PropertyName, value); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.String; }
/// <summary> /// Writes the property name and <see cref="DateTimeOffset"/> value (as a JSON string) 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 string 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="DateTimeOffset"/> using the round-trippable ('O') <see cref="StandardFormat"/> , for example: 2017-06-12T05:30:45.7680000-07:00. /// </remarks> public void WriteString(ReadOnlySpan <char> propertyName, DateTimeOffset value, bool escape = true) { JsonWriterHelper.ValidateProperty(propertyName); if (escape) { WriteStringEscape(propertyName, value); } else { WriteStringByOptions(propertyName, value); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.String; }
public void WriteNumber(ReadOnlySpan <char> propertyName, ulong value, bool escape = true) { JsonWriterHelper.ValidateProperty(propertyName); if (escape) { WriteNumberEscape(propertyName, value); } else { WriteNumberByOptions(propertyName, 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; }
/// <summary> /// Writes the property name and the JSON literal "null" 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="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> public void WriteNull(ReadOnlySpan <char> propertyName, bool escape = true) { JsonWriterHelper.ValidateProperty(propertyName); ReadOnlySpan <byte> span = JsonConstants.NullValue; if (escape) { WriteLiteralEscape(propertyName, span); } else { WriteLiteralByOptions(propertyName, span); } SetFlagToAddListSeparatorBeforeNextItem(); _tokenType = JsonTokenType.Null; }