public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktRating obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Rating.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_RATING, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Rating, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Votes.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_VOTES, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Votes, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Distribution?.Count > 0)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_DISTRIBUTION, cancellationToken).ConfigureAwait(false);

                await JsonWriterHelper.WriteDistributionAsync(jsonWriter, obj.Distribution, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserRatingsStatistics obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Total.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_RATINGS_STATISTICS_PROPERTY_NAME_TOTAL, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Total, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Distribution != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_RATINGS_STATISTICS_PROPERTY_NAME_DISTRIBUTION, cancellationToken).ConfigureAwait(false);

                await JsonWriterHelper.WriteDistributionAsync(jsonWriter, obj.Distribution, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #3
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserRatingsStatistics obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Total.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_TOTAL, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Total, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Distribution != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_DISTRIBUTION, cancellationToken).ConfigureAwait(false);

                await JsonWriterHelper.WriteDistributionAsync(jsonWriter, obj.Distribution, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }