diff --git a/.vscode/settings.json b/.vscode/settings.json index 851f13bf..58987349 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,8 @@ "editor.detectIndentation": false, "editor.insertSpaces": true, "editor.tabSize": 2, + "omnisharp.enableEditorConfigSupport": true, "files.associations": { "*.md": "mdx" - }, + } } diff --git a/SpotifyAPI.Web.Auth/AuthException.cs b/SpotifyAPI.Web.Auth/AuthException.cs index 41e1bdf3..aec059fb 100644 --- a/SpotifyAPI.Web.Auth/AuthException.cs +++ b/SpotifyAPI.Web.Auth/AuthException.cs @@ -3,7 +3,7 @@ namespace SpotifyAPI.Web.Auth [System.Serializable] public class AuthException : System.Exception { - public AuthException(string error, string state) + public AuthException(string? error, string? state) { Error = error; State = state; diff --git a/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs b/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs index 97cb7d99..42de59e7 100644 --- a/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs +++ b/SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs @@ -35,16 +35,17 @@ namespace SpotifyAPI.Web.Auth .WithModule(new ActionModule("/", HttpVerbs.Post, (ctx) => { var query = ctx.Request.QueryString; - if (query["error"] != null) + var error = query["error"]; + if (error != null) { - throw new AuthException(query["error"], query["state"]); + throw new AuthException(error, query["state"]); } var requestType = query.Get("request_type"); if (requestType == "token") { ImplictGrantReceived?.Invoke(this, new ImplictGrantResponse( - query["access_token"], query["token_type"], int.Parse(query["expires_in"]) + query["access_token"]!, query["token_type"]!, int.Parse(query["expires_in"]!) ) { State = query["state"] @@ -52,7 +53,7 @@ namespace SpotifyAPI.Web.Auth } if (requestType == "code") { - AuthorizationCodeReceived?.Invoke(this, new AuthorizationCodeResponse(query["code"]) + AuthorizationCodeReceived?.Invoke(this, new AuthorizationCodeResponse(query["code"]!) { State = query["state"] }); diff --git a/SpotifyAPI.Web.Auth/Models/Response/AuthorizationCodeResponse.cs b/SpotifyAPI.Web.Auth/Models/Response/AuthorizationCodeResponse.cs index 13d43608..b83bec2a 100644 --- a/SpotifyAPI.Web.Auth/Models/Response/AuthorizationCodeResponse.cs +++ b/SpotifyAPI.Web.Auth/Models/Response/AuthorizationCodeResponse.cs @@ -10,6 +10,6 @@ namespace SpotifyAPI.Web.Auth } public string Code { get; set; } = default!; - public string State { get; set; } = default!; + public string? State { get; set; } = default!; } } diff --git a/SpotifyAPI.Web.Auth/Models/Response/ImplicitGrantResponse.cs b/SpotifyAPI.Web.Auth/Models/Response/ImplicitGrantResponse.cs index 2950923e..7f8e256f 100644 --- a/SpotifyAPI.Web.Auth/Models/Response/ImplicitGrantResponse.cs +++ b/SpotifyAPI.Web.Auth/Models/Response/ImplicitGrantResponse.cs @@ -17,7 +17,7 @@ namespace SpotifyAPI.Web.Auth public string AccessToken { get; set; } = default!; public string TokenType { get; set; } = default!; public int ExpiresIn { get; set; } - public string State { get; set; } = default!; + public string? State { get; set; } = default!; /// /// Auto-Initalized to UTC Now diff --git a/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj b/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj index 6abdd41d..8f47dbe7 100644 --- a/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj +++ b/SpotifyAPI.Web.Auth/SpotifyAPI.Web.Auth.csproj @@ -1,7 +1,7 @@  - netstandard2.1;netstandard2.0 - 8.0 + net5.0;netstandard2.1;netstandard2.0 + 9.0 enable SpotifyAPI.Web.Auth SpotifyAPI.Web.Auth diff --git a/SpotifyAPI.Web.Examples/Example.ASP/Example.ASP.csproj b/SpotifyAPI.Web.Examples/Example.ASP/Example.ASP.csproj index 823fc83b..21fde54d 100644 --- a/SpotifyAPI.Web.Examples/Example.ASP/Example.ASP.csproj +++ b/SpotifyAPI.Web.Examples/Example.ASP/Example.ASP.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 da29eac4-4c22-4a7f-b393-379e83b60998 diff --git a/SpotifyAPI.Web.Examples/Example.ASPBlazor/App.razor b/SpotifyAPI.Web.Examples/Example.ASPBlazor/App.razor index bf6c7737..38f2a1c4 100644 --- a/SpotifyAPI.Web.Examples/Example.ASPBlazor/App.razor +++ b/SpotifyAPI.Web.Examples/Example.ASPBlazor/App.razor @@ -1,11 +1,10 @@ - - - - - - - -

Sorry, there's nothing at this address.

-
-
+ + + + + + +

Sorry, there's nothing at this address.

+
+
diff --git a/SpotifyAPI.Web.Examples/Example.ASPBlazor/Example.ASPBlazor.csproj b/SpotifyAPI.Web.Examples/Example.ASPBlazor/Example.ASPBlazor.csproj index f8ff38d1..4ec3d7a1 100644 --- a/SpotifyAPI.Web.Examples/Example.ASPBlazor/Example.ASPBlazor.csproj +++ b/SpotifyAPI.Web.Examples/Example.ASPBlazor/Example.ASPBlazor.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/SpotifyAPI.Web.Examples/Example.BlazorWASM/App.razor b/SpotifyAPI.Web.Examples/Example.BlazorWASM/App.razor index 6f67a6ea..2d39d607 100644 --- a/SpotifyAPI.Web.Examples/Example.BlazorWASM/App.razor +++ b/SpotifyAPI.Web.Examples/Example.BlazorWASM/App.razor @@ -1,10 +1,10 @@ - - - - - -

Sorry, there's nothing at this address.

-
-
+ + + + + +

Sorry, there's nothing at this address.

+
+
diff --git a/SpotifyAPI.Web.Examples/Example.BlazorWASM/Example.BlazorWASM.csproj b/SpotifyAPI.Web.Examples/Example.BlazorWASM/Example.BlazorWASM.csproj index adb230ee..4999ca13 100644 --- a/SpotifyAPI.Web.Examples/Example.BlazorWASM/Example.BlazorWASM.csproj +++ b/SpotifyAPI.Web.Examples/Example.BlazorWASM/Example.BlazorWASM.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + net5.0 3.0 diff --git a/SpotifyAPI.Web.Examples/Example.CLI.CustomHTML/Example.CLI.CustomHTML.csproj b/SpotifyAPI.Web.Examples/Example.CLI.CustomHTML/Example.CLI.CustomHTML.csproj index 53f289a9..12043086 100644 --- a/SpotifyAPI.Web.Examples/Example.CLI.CustomHTML/Example.CLI.CustomHTML.csproj +++ b/SpotifyAPI.Web.Examples/Example.CLI.CustomHTML/Example.CLI.CustomHTML.csproj @@ -6,8 +6,8 @@
+ net5.0 Exe - netcoreapp3.1 diff --git a/SpotifyAPI.Web.Examples/Example.TokenSwap/Client/Client.csproj b/SpotifyAPI.Web.Examples/Example.TokenSwap/Client/Client.csproj index 49665eb7..e57fedf9 100644 --- a/SpotifyAPI.Web.Examples/Example.TokenSwap/Client/Client.csproj +++ b/SpotifyAPI.Web.Examples/Example.TokenSwap/Client/Client.csproj @@ -6,8 +6,8 @@ + net5.0 Exe - netcoreapp3.1
diff --git a/SpotifyAPI.Web.Tests/SpotifyAPI.Web.Tests.csproj b/SpotifyAPI.Web.Tests/SpotifyAPI.Web.Tests.csproj index b720ec21..fb1f3989 100644 --- a/SpotifyAPI.Web.Tests/SpotifyAPI.Web.Tests.csproj +++ b/SpotifyAPI.Web.Tests/SpotifyAPI.Web.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;netcoreapp2.2 + net5.0;netcoreapp3.1;netcoreapp2.2 false diff --git a/SpotifyAPI.Web/Clients/OAuthClient.cs b/SpotifyAPI.Web/Clients/OAuthClient.cs index dd2b77c4..06bfb7c8 100644 --- a/SpotifyAPI.Web/Clients/OAuthClient.cs +++ b/SpotifyAPI.Web/Clients/OAuthClient.cs @@ -112,13 +112,13 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("client_id", request.ClientId), - new KeyValuePair("grant_type", "authorization_code"), - new KeyValuePair("code", request.Code), - new KeyValuePair("redirect_uri", request.RedirectUri.ToString()), - new KeyValuePair("code_verifier", request.CodeVerifier), + new KeyValuePair("client_id", request.ClientId), + new KeyValuePair("grant_type", "authorization_code"), + new KeyValuePair("code", request.Code), + new KeyValuePair("redirect_uri", request.RedirectUri.ToString()), + new KeyValuePair("code_verifier", request.CodeVerifier), }; return SendOAuthRequest(apiConnector, form, null, null); @@ -129,11 +129,11 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("client_id", request.ClientId), - new KeyValuePair("grant_type", "refresh_token"), - new KeyValuePair("refresh_token", request.RefreshToken), + new KeyValuePair("client_id", request.ClientId), + new KeyValuePair("grant_type", "refresh_token"), + new KeyValuePair("refresh_token", request.RefreshToken), }; return SendOAuthRequest(apiConnector, form, null, null); @@ -146,9 +146,9 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("refresh_token", request.RefreshToken) + new KeyValuePair("refresh_token", request.RefreshToken) }; #pragma warning disable CA2000 return apiConnector.Post( @@ -164,9 +164,9 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("code", request.Code) + new KeyValuePair("code", request.Code) }; #pragma warning disable CA2000 @@ -183,9 +183,9 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("grant_type", "client_credentials") + new KeyValuePair("grant_type", "client_credentials") }; return SendOAuthRequest(apiConnector, form, request.ClientId, request.ClientSecret); @@ -198,10 +198,10 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("grant_type", "refresh_token"), - new KeyValuePair("refresh_token", request.RefreshToken) + new KeyValuePair("grant_type", "refresh_token"), + new KeyValuePair("refresh_token", request.RefreshToken) }; return SendOAuthRequest(apiConnector, form, request.ClientId, request.ClientSecret); @@ -214,11 +214,11 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(apiConnector, nameof(apiConnector)); - var form = new List> + var form = new List> { - new KeyValuePair("grant_type", "authorization_code"), - new KeyValuePair("code", request.Code), - new KeyValuePair("redirect_uri", request.RedirectUri.ToString()) + new KeyValuePair("grant_type", "authorization_code"), + new KeyValuePair("code", request.Code), + new KeyValuePair("redirect_uri", request.RedirectUri.ToString()) }; return SendOAuthRequest(apiConnector, form, request.ClientId, request.ClientSecret); @@ -226,7 +226,7 @@ namespace SpotifyAPI.Web private static Task SendOAuthRequest( IAPIConnector apiConnector, - List> form, + List> form, string? clientId, string? clientSecret) { diff --git a/SpotifyAPI.Web/Clients/SimplePaginator.cs b/SpotifyAPI.Web/Clients/SimplePaginator.cs index 92f35dac..b6e2c2e1 100644 --- a/SpotifyAPI.Web/Clients/SimplePaginator.cs +++ b/SpotifyAPI.Web/Clients/SimplePaginator.cs @@ -25,11 +25,17 @@ namespace SpotifyAPI.Web var page = firstPage; var results = new List(); - results.AddRange(firstPage.Items); + if (page.Items != null) + { + results.AddRange(page.Items); + } while (page.Next != null && await ShouldContinue(results, page).ConfigureAwait(false)) { page = await connector.Get>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false); - results.AddRange(page.Items); + if (page.Items != null) + { + results.AddRange(page.Items); + } } return results; @@ -45,12 +51,18 @@ namespace SpotifyAPI.Web var page = firstPage; var results = new List(); - results.AddRange(firstPage.Items); + if (page.Items != null) + { + results.AddRange(page.Items); + } while (page.Next != null && await ShouldContinue(results, page).ConfigureAwait(false)) { var next = await connector.Get(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false); page = mapper(next); - results.AddRange(page.Items); + if (page.Items != null) + { + results.AddRange(page.Items); + } } return results; diff --git a/SpotifyAPI.Web/Clients/SpotifyClient.cs b/SpotifyAPI.Web/Clients/SpotifyClient.cs index 8439ce28..31bcad71 100644 --- a/SpotifyAPI.Web/Clients/SpotifyClient.cs +++ b/SpotifyAPI.Web/Clients/SpotifyClient.cs @@ -191,7 +191,7 @@ namespace SpotifyAPI.Web var firstPage = await getFirstPage().ConfigureAwait(false); await foreach (var item in (paginator ?? DefaultPaginator) - .Paginate(firstPage, mapper, _apiConnector) + .Paginate(firstPage, mapper, _apiConnector, cancellationToken) .WithCancellation(cancellationToken) ) { @@ -223,7 +223,7 @@ namespace SpotifyAPI.Web var firstPage = await firstPageTask.ConfigureAwait(false); await foreach (var item in (paginator ?? DefaultPaginator) - .Paginate(firstPage, mapper, _apiConnector) + .Paginate(firstPage, mapper, _apiConnector, cancellationToken) .WithCancellation(cancellationToken) ) { diff --git a/SpotifyAPI.Web/Exceptions/APITooManyRequestsException.cs b/SpotifyAPI.Web/Exceptions/APITooManyRequestsException.cs index acfdac69..2ea206dd 100644 --- a/SpotifyAPI.Web/Exceptions/APITooManyRequestsException.cs +++ b/SpotifyAPI.Web/Exceptions/APITooManyRequestsException.cs @@ -14,7 +14,7 @@ namespace SpotifyAPI.Web { Ensure.ArgumentNotNull(response, nameof(response)); - if (response.Headers.TryGetValue("Retry-After", out string retryAfter)) + if (response.Headers.TryGetValue("Retry-After", out string? retryAfter)) { RetryAfter = TimeSpan.FromSeconds(int.Parse(retryAfter, CultureInfo.InvariantCulture)); } diff --git a/SpotifyAPI.Web/Http/APIConnector.cs b/SpotifyAPI.Web/Http/APIConnector.cs index e75069e8..ecc24862 100644 --- a/SpotifyAPI.Web/Http/APIConnector.cs +++ b/SpotifyAPI.Web/Http/APIConnector.cs @@ -254,7 +254,7 @@ namespace SpotifyAPI.Web.Http { var request = CreateRequest(uri, method, parameters, body, headers); IAPIResponse apiResponse = await DoSerializedRequest(request).ConfigureAwait(false); - return apiResponse.Body; + return apiResponse.Body!; } public async Task SendAPIRequestDetailed( diff --git a/SpotifyAPI.Web/Http/APIResponse.cs b/SpotifyAPI.Web/Http/APIResponse.cs index 48e0ba47..6700a17e 100644 --- a/SpotifyAPI.Web/Http/APIResponse.cs +++ b/SpotifyAPI.Web/Http/APIResponse.cs @@ -2,7 +2,7 @@ namespace SpotifyAPI.Web.Http { public class APIResponse : IAPIResponse { - public APIResponse(IResponse response, T body = default) + public APIResponse(IResponse response, T? body = default) { Ensure.ArgumentNotNull(response, nameof(response)); @@ -10,7 +10,7 @@ namespace SpotifyAPI.Web.Http Response = response; } - public T Body { get; set; } + public T? Body { get; set; } public IResponse Response { get; set; } } diff --git a/SpotifyAPI.Web/Http/Interfaces/IAPIResponse.cs b/SpotifyAPI.Web/Http/Interfaces/IAPIResponse.cs index 2de5db76..aa2513be 100644 --- a/SpotifyAPI.Web/Http/Interfaces/IAPIResponse.cs +++ b/SpotifyAPI.Web/Http/Interfaces/IAPIResponse.cs @@ -2,7 +2,7 @@ namespace SpotifyAPI.Web.Http { public interface IAPIResponse { - T Body { get; } + T? Body { get; } IResponse Response { get; } } diff --git a/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs b/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs index d202f70b..9fb3e0ae 100644 --- a/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs +++ b/SpotifyAPI.Web/Http/SimpleConsoleHTTPLogger.cs @@ -15,7 +15,9 @@ namespace SpotifyAPI.Web.Http string? parameters = null; if (request.Parameters != null) { - parameters = string.Join(",", request.Parameters?.Select(kv => kv.Key + "=" + kv.Value).ToArray()); + parameters = string.Join(",", + request.Parameters?.Select(kv => kv.Key + "=" + kv.Value)?.ToArray() ?? Array.Empty() + ); } Console.WriteLine(OnRequestFormat, request.Method, request.Endpoint, parameters, request.Body); @@ -28,7 +30,7 @@ namespace SpotifyAPI.Web.Http #if NETSTANDARD2_0 string? body = response.Body?.ToString().Replace("\n", ""); #else - string? body = response.Body?.ToString().Replace("\n", "", StringComparison.InvariantCulture); + string? body = response.Body?.ToString()?.Replace("\n", "", StringComparison.InvariantCulture); #endif body = body?.Substring(0, Math.Min(50, body?.Length ?? 0)); diff --git a/SpotifyAPI.Web/Models/Request/RequestParams.cs b/SpotifyAPI.Web/Models/Request/RequestParams.cs index d5cc3319..97a05bd7 100644 --- a/SpotifyAPI.Web/Models/Request/RequestParams.cs +++ b/SpotifyAPI.Web/Models/Request/RequestParams.cs @@ -37,9 +37,12 @@ namespace SpotifyAPI.Web _bodyParamsCache[type] = new List<(PropertyInfo, BodyParamAttribute)>(); foreach (var prop in bodyProps) { - var attribute = (BodyParamAttribute)prop.GetCustomAttribute(typeof(BodyParamAttribute)); - _bodyParamsCache[type].Add((prop, attribute)); - AddBodyParam(body, prop, attribute); + var attribute = prop.GetCustomAttribute(); + if (attribute != null) + { + _bodyParamsCache[type].Add((prop, attribute)); + AddBodyParam(body, prop, attribute); + } } } @@ -48,7 +51,7 @@ namespace SpotifyAPI.Web private void AddBodyParam(JObject body, PropertyInfo prop, BodyParamAttribute attribute) { - object value = prop.GetValue(this); + object? value = prop.GetValue(this); if (value != null) { body[attribute.Key ?? prop.Name] = JToken.FromObject(value); @@ -81,9 +84,12 @@ namespace SpotifyAPI.Web _queryParamsCache[type] = new List<(PropertyInfo, QueryParamAttribute)>(); foreach (var prop in queryProps) { - var attribute = (QueryParamAttribute)prop.GetCustomAttribute(typeof(QueryParamAttribute)); - _queryParamsCache[type].Add((prop, attribute)); - AddQueryParam(queryParams, prop, attribute); + var attribute = prop.GetCustomAttribute(); + if (attribute != null) + { + _queryParamsCache[type].Add((prop, attribute)); + AddQueryParam(queryParams, prop, attribute); + } } } @@ -94,7 +100,7 @@ namespace SpotifyAPI.Web private void AddQueryParam(Dictionary queryParams, PropertyInfo prop, QueryParamAttribute attribute) { - object value = prop.GetValue(this); + object? value = prop.GetValue(this); if (value != null) { if (value is IList list) @@ -140,7 +146,7 @@ namespace SpotifyAPI.Web } else { - queryParams.Add(attribute.Key ?? prop.Name, value.ToString()); + queryParams.Add(attribute.Key ?? prop.Name, value.ToString() ?? throw new Exception("ToString was null on a value")); } } } diff --git a/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs b/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs index 63ff0ef4..9bb5f348 100644 --- a/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs +++ b/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs @@ -70,6 +70,7 @@ namespace SpotifyAPI.Web public Task HandleRetry(IRequest request, IResponse response, IRetryHandler.RetryFunc retry) { Ensure.ArgumentNotNull(response, nameof(response)); + Ensure.ArgumentNotNull(retry, nameof(retry)); return HandleRetryInternally(request, response, retry, RetryTimes); } diff --git a/SpotifyAPI.Web/SpotifyAPI.Web.csproj b/SpotifyAPI.Web/SpotifyAPI.Web.csproj index 7dd57e95..9d1cd506 100644 --- a/SpotifyAPI.Web/SpotifyAPI.Web.csproj +++ b/SpotifyAPI.Web/SpotifyAPI.Web.csproj @@ -1,8 +1,8 @@  - netstandard2.1;netstandard2.0 - 8.0 + net5.0;netstandard2.1;netstandard2.0 + 9.0 enable SpotifyAPI.Web SpotifyAPI.Web diff --git a/SpotifyAPI.Web/Util/StringAttribute.cs b/SpotifyAPI.Web/Util/StringAttribute.cs index d0d54873..d54e39df 100644 --- a/SpotifyAPI.Web/Util/StringAttribute.cs +++ b/SpotifyAPI.Web/Util/StringAttribute.cs @@ -15,11 +15,10 @@ namespace SpotifyAPI.Web public string Value { get; set; } -#if NETSTANDARD2_1 - public static bool GetValue(Type enumType, Enum enumValue, [NotNullWhen(true)] out string? result) -#endif #if NETSTANDARD2_0 public static bool GetValue(Type enumType, Enum enumValue, out string? result) +#else + public static bool GetValue(Type enumType, Enum enumValue, [NotNullWhen(true)] out string? result) #endif { Ensure.ArgumentNotNull(enumType, nameof(enumType)); diff --git a/SpotifyAPI.Web/Util/URIExtension.cs b/SpotifyAPI.Web/Util/URIExtension.cs index c5d3a478..eae2e87d 100644 --- a/SpotifyAPI.Web/Util/URIExtension.cs +++ b/SpotifyAPI.Web/Util/URIExtension.cs @@ -19,9 +19,9 @@ namespace SpotifyAPI.Web var newParameters = new Dictionary(); NameValueCollection existingParameters = HttpUtility.ParseQueryString(uri.Query); - foreach (string key in existingParameters.AllKeys) + foreach (string key in existingParameters) { - newParameters.Add(key, existingParameters[key]); + newParameters.Add(key, existingParameters[key]!); } foreach (KeyValuePair parameter in parameters) { diff --git a/SpotifyAPI.Web/Util/URIParameterFormatProvider.cs b/SpotifyAPI.Web/Util/URIParameterFormatProvider.cs index 6fbcd81a..3fb91a1f 100644 --- a/SpotifyAPI.Web/Util/URIParameterFormatProvider.cs +++ b/SpotifyAPI.Web/Util/URIParameterFormatProvider.cs @@ -11,16 +11,16 @@ namespace SpotifyAPI.Web _formatter = new URIParameterFormatter(); } - public object? GetFormat(Type formatType) + public object? GetFormat(Type? formatType) { return formatType == typeof(ICustomFormatter) ? _formatter : null; } private class URIParameterFormatter : ICustomFormatter { - public string Format(string format, object arg, IFormatProvider formatProvider) + public string Format(string? format, object? arg, IFormatProvider? formatProvider) { - return HttpUtility.UrlEncode(arg.ToString()); + return HttpUtility.UrlEncode(arg?.ToString()) ?? string.Empty; } } }