Exemple #1
0
        public override async Task <ITraktCastAndCrew> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktCastAndCrew)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var castReader = new CastMemberArrayJsonReader();
                var crewReader = new CrewObjectJsonReader();
                ITraktCastAndCrew traktCastAndCrew = new TraktCastAndCrew();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.CAST_AND_CREW_PROPERTY_NAME_CAST:
                        traktCastAndCrew.Cast = await castReader.ReadArrayAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.CAST_AND_CREW_PROPERTY_NAME_CREW:
                        traktCastAndCrew.Crew = await crewReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktCastAndCrew);
            }

            return(await Task.FromResult(default(ITraktCastAndCrew)));
        }
        public override async Task <IEnumerable <ITraktCrew> > ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(IEnumerable <ITraktCrew>)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var        crewReader = new CrewObjectJsonReader();
                var        crews      = new List <ITraktCrew>();
                ITraktCrew crew       = await crewReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (crew != null)
                {
                    crews.Add(crew);
                    crew = await crewReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                return(crews);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktCrew>)));
        }