Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        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);
Exemplo n.º 4
0
 public void WriteNumber(JsonEncodedText propertyName, uint value)
 => WriteNumber(propertyName, (ulong)value);
Exemplo n.º 5
0
 /// <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);
Exemplo n.º 6
0
 /// <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;
 }
Exemplo n.º 10
0
 public void WriteNumber(JsonEncodedText text, int x)
 {
 }
Exemplo n.º 11
0
 public void WriteNull(JsonEncodedText text)
 {
 }
Exemplo n.º 12
0
 public void WritePropertyName(JsonEncodedText text)
 {
 }
Exemplo n.º 13
0
 public void WriteString(JsonEncodedText text, string str)
 {
 }
Exemplo n.º 14
0
 public void WriteString(JsonEncodedText text, DateTimeOffset timestamp)
 {
 }
Exemplo n.º 15
0
 public void WriteString(JsonEncodedText text, JsonEncodedText value)
 {
 }
Exemplo n.º 16
0
 public void WriteString(JsonEncodedText text, ReadOnlySpan <byte> span)
 {
 }