private void WriteObjectOrArrayStart(ClassType classType, JsonEncodedText propertyName, Utf8JsonWriter writer, bool writeNull) { if (writeNull) { writer.WriteNull(propertyName); } else if (classType == ClassType.Object || classType == ClassType.Dictionary || classType == ClassType.IDictionaryConstructible) { writer.WriteStartObject(propertyName); StartObjectWritten = true; } else { Debug.Assert(classType == ClassType.Enumerable); writer.WriteStartArray(propertyName); } }
private void DeterminePropertyName() { if (PropertyInfo == null) { return; } JsonPropertyNameAttribute?nameAttribute = GetAttribute <JsonPropertyNameAttribute>(PropertyInfo); if (nameAttribute != null) { string name = nameAttribute.Name; if (name == null) { ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameNull(ParentClassType, this); } NameAsString = name; } else if (Options.PropertyNamingPolicy != null) { string name = Options.PropertyNamingPolicy.ConvertName(PropertyInfo.Name); if (name == null) { ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameNull(ParentClassType, this); } NameAsString = name; } else { NameAsString = PropertyInfo.Name; } Debug.Assert(NameAsString != null); // At this point propertyName is valid UTF16, so just call the simple UTF16->UTF8 encoder. NameAsUtf8Bytes = Encoding.UTF8.GetBytes(NameAsString); // Cache the escaped property name. EscapedName = JsonEncodedText.Encode(NameAsString, NameAsUtf8Bytes, Options.Encoder); }
public void WriteNumber(JsonEncodedText propertyName, ulong value) => WriteNumberHelper(propertyName.EncodedUtf8Bytes, value);
public void WriteNumber(JsonEncodedText propertyName, uint value) => WriteNumber(propertyName, (ulong)value);
/// <summary> /// Writes the pre-encoded text value (as a JSON string) as an element of a JSON array. /// </summary> /// <param name="value">The JSON-encoded value to write.</param> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in invalid JSON being written (while validation is enabled). /// </exception> public void WriteStringValue(JsonEncodedText value) => WriteStringValueHelper(value.EncodedUtf8Bytes);
/// <summary> /// Writes the pre-encoded 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 JSON-encoded name of the property to write.</param> /// <param name="value">The value to 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="DateTimeOffset"/> using the round-trippable ('O') <see cref="StandardFormat"/> , for example: 2017-06-12T05:30:45.7680000-07:00. /// </remarks> public void WriteString(JsonEncodedText propertyName, DateTimeOffset value) => WriteStringHelper(propertyName.EncodedUtf8Bytes, value);
/// <summary> /// Writes the pre-encoded property name and raw bytes value (as a base 64 encoded JSON string) as part of a name/value pair of a JSON object. /// </summary> /// <param name="propertyName">The JSON encoded property name of the JSON object to be transcoded and written as UTF-8.</param> /// <param name="bytes">The binary data to be written as a base 64 encoded JSON string as part of the name/value pair.</param> /// <remarks> /// The property name should already be escaped when the instance of <see cref="JsonEncodedText"/> was created. /// </remarks> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in an invalid JSON to be written (while validation is enabled). /// </exception> public void WriteBase64String(JsonEncodedText propertyName, ReadOnlySpan <byte> bytes) => WriteBase64StringHelper(propertyName.EncodedUtf8Bytes, bytes);
/// <summary> /// Writes the pre-encoded 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 JSON 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> /// <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. /// The property name should already be escaped when the instance of <see cref="JsonEncodedText"/> was created. /// </remarks> public void WriteString(JsonEncodedText propertyName, Guid value) => WriteStringHelper(propertyName.EncodedUtf8Bytes, value);
/// <summary> /// Writes the pre-encoded property name and the JSON literal "null" 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> /// <exception cref="InvalidOperationException"> /// Thrown if this would result in invalid JSON being written (while validation is enabled). /// </exception> public void WriteNull(JsonEncodedText propertyName) { WriteLiteralHelper(propertyName.EncodedUtf8Bytes, JsonConstants.NullValue); _tokenType = JsonTokenType.Null; }
public void WriteNumber(JsonEncodedText text, int x) { }
public void WriteNull(JsonEncodedText text) { }
public void WritePropertyName(JsonEncodedText text) { }
public void WriteString(JsonEncodedText text, string str) { }
public void WriteString(JsonEncodedText text, DateTimeOffset timestamp) { }
public void WriteString(JsonEncodedText text, JsonEncodedText value) { }
public void WriteString(JsonEncodedText text, ReadOnlySpan <byte> span) { }