public static Task <Album> GetFullDetailsAsync( this SimplifiedAlbum album, HttpClient httpClient, IAccessTokenProvider accessTokenProvider, CancellationToken cancellationToken = default) { if (album is Album original) { return(Task.FromResult(original)); } return(httpClient.GetAsync <Album>(album.Href, accessTokenProvider, cancellationToken)); }
public override Track Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType is not JsonTokenType.StartObject) { throw new JsonException(); } var countryCodeArrayConverter = options.GetConverter <CountryCodeArray>(); var externalIdsConverter = options.GetConverter <ExternalIds>(); var externalUrlsConverter = options.GetConverter <ExternalUrls>(); var simplifiedAlbumConverter = options.GetConverter <SimplifiedAlbum>(); var simplifiedArtistArrayConverter = options.GetConverter <SimplifiedArtistArray>(); var uriConverter = options.GetConverter <Uri>(); string id = string.Empty; Uri uri = null !; Uri href = null !; string name = string.Empty; SimplifiedAlbum album = null !; SimplifiedArtistArray artists = Array.Empty <SimplifiedArtist>(); int duration = default; int trackNumber = default; int discNumber = default; bool isExplicit = default; bool isLocal = default; CountryCodeArray availableMarkets = Array.Empty <CountryCode>(); int popularity = default; string previewUrl = string.Empty; ExternalIds externalIds = null !; ExternalUrls externalUrls = null !; while (reader.Read()) { if (reader.TokenType is JsonTokenType.EndObject) { break; } if (reader.TokenType is not JsonTokenType.PropertyName) { throw new JsonException(); } var propertyName = reader.GetString(); reader.Read(); // Read to next token. switch (propertyName) { case "id": id = reader.GetString() !; break; case "uri": uri = uriConverter.Read(ref reader, typeof(Uri), options) !; break; case "href": href = uriConverter.Read(ref reader, typeof(Uri), options) !; break; case "name": name = reader.GetString() !; break; case "album": album = simplifiedAlbumConverter.Read(ref reader, typeof(SimplifiedAlbum), options) !; break; case "artists": artists = simplifiedArtistArrayConverter.Read(ref reader, typeof(SimplifiedArtistArray), options) !; break; case "duration_ms": duration = reader.GetInt32(); break; case "track_number": trackNumber = reader.GetInt32(); break; case "disc_number": discNumber = reader.GetInt32(); break; case "explicit": isExplicit = reader.GetBoolean(); break; case "is_local": isLocal = reader.GetBoolean(); break; case "available_markets": availableMarkets = countryCodeArrayConverter.Read(ref reader, typeof(CountryCodeArray), options) !; break; case "popularity": popularity = reader.GetInt32(); break; case "preview_url": previewUrl = reader.GetString() !; break; case "external_ids": externalIds = externalIdsConverter.Read(ref reader, typeof(ExternalIds), options) !; break; case "external_urls": externalUrls = externalUrlsConverter.Read(ref reader, typeof(ExternalUrls), options) !; break; default: reader.Skip(); break; } } return(new( id, uri, href, name, album, artists, duration, discNumber, trackNumber, isExplicit, isLocal, availableMarkets, popularity, previewUrl, externalIds, externalUrls)); }