예제 #1
0
        /// <summary>
        /// Writes the content of the entity to JSON (asynchronious way)
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="options">Some read/write options.</param>
        /// <returns>Task.</returns>
        public async Task WriteToJsonAsync(JsonWriter writer, BitOptions options)
        {
            await writer.WriteStartObjectAsync().ConfigureAwait(false);

            await WritePropertiesToJsonAsync(writer).ConfigureAwait(false);

            await writer.WritePropertyNameAsync("attrs").ConfigureAwait(false);

            await Attributes.WriteToJsonAsync(writer, options).ConfigureAwait(false);

            if (SubEntities.Count > 0)
            {
                await writer.WritePropertyNameAsync("ents").ConfigureAwait(false);

                await SubEntities.WriteToJsonAsync(writer, options).ConfigureAwait(false);
            }

            await writer.WriteEndObjectAsync().ConfigureAwait(false);
        }
예제 #2
0
        /// <summary>
        /// Writes the content of the entity to JSON (asynchronious way)
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="options">Some read/write options.</param>
        /// <param name="ct">The cancellation token.</param>
        /// <returns>Task.</returns>
        public async Task WriteToJsonAsync(JsonWriter writer, BitOptions options, CancellationToken ct = default)
        {
            await writer.WriteStartObjectAsync(ct).ConfigureAwait(false);

            await WritePropertiesToJsonAsync(writer, ct).ConfigureAwait(false);

            await writer.WritePropertyNameAsync("attrs", ct).ConfigureAwait(false);

            await Attributes.WriteToJsonAsync(writer, options, ct).ConfigureAwait(false);

            if (SubEntities.Count > 0)
            {
                await writer.WritePropertyNameAsync("ents", ct).ConfigureAwait(false);

                await SubEntities.WriteToJsonAsync(writer, options, ct).ConfigureAwait(false);
            }

            await writer.WriteEndObjectAsync(ct).ConfigureAwait(false);
        }