diff --git a/SpotifyAPI.Web.Examples/Example.ASPBlazor/Pages/Index.razor b/SpotifyAPI.Web.Examples/Example.ASPBlazor/Pages/Index.razor index abf6f3a0..d669463b 100644 --- a/SpotifyAPI.Web.Examples/Example.ASPBlazor/Pages/Index.razor +++ b/SpotifyAPI.Web.Examples/Example.ASPBlazor/Pages/Index.razor @@ -26,7 +26,7 @@ else private PrivateUser _me; - private int _totalPlaylistCount; + private int? _totalPlaylistCount; protected override void OnInitialized() { diff --git a/SpotifyAPI.Web.Examples/Example.BlazorWASM/Pages/Index.razor b/SpotifyAPI.Web.Examples/Example.BlazorWASM/Pages/Index.razor index 7e277b1c..a222de81 100644 --- a/SpotifyAPI.Web.Examples/Example.BlazorWASM/Pages/Index.razor +++ b/SpotifyAPI.Web.Examples/Example.BlazorWASM/Pages/Index.razor @@ -33,7 +33,7 @@ else private PrivateUser _me; - private int _totalPlaylistCount; + private int? _totalPlaylistCount; private Uri _authUri; diff --git a/SpotifyAPI.Web/Clients/SimplePaginator.cs b/SpotifyAPI.Web/Clients/SimplePaginator.cs index b15c0958..92f35dac 100644 --- a/SpotifyAPI.Web/Clients/SimplePaginator.cs +++ b/SpotifyAPI.Web/Clients/SimplePaginator.cs @@ -64,6 +64,10 @@ namespace SpotifyAPI.Web { Ensure.ArgumentNotNull(firstPage, nameof(firstPage)); Ensure.ArgumentNotNull(connector, nameof(connector)); + if (firstPage.Items == null) + { + throw new ArgumentException("The first page has to contain an Items list!", nameof(firstPage)); + } var page = firstPage; foreach (var item in page.Items) @@ -73,7 +77,7 @@ namespace SpotifyAPI.Web while (page.Next != null) { page = await connector.Get>(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false); - foreach (var item in page.Items) + foreach (var item in page.Items!) { yield return item; } @@ -89,6 +93,10 @@ namespace SpotifyAPI.Web Ensure.ArgumentNotNull(firstPage, nameof(firstPage)); Ensure.ArgumentNotNull(mapper, nameof(mapper)); Ensure.ArgumentNotNull(connector, nameof(connector)); + if (firstPage.Items == null) + { + throw new ArgumentException("The first page has to contain an Items list!", nameof(firstPage)); + } var page = firstPage; foreach (var item in page.Items) @@ -99,7 +107,7 @@ namespace SpotifyAPI.Web { var next = await connector.Get(new Uri(page.Next, UriKind.Absolute)).ConfigureAwait(false); page = mapper(next); - foreach (var item in page.Items) + foreach (var item in page.Items!) { yield return item; } diff --git a/SpotifyAPI.Web/Models/IPaginatable.cs b/SpotifyAPI.Web/Models/IPaginatable.cs index e5752bc8..682c5ac1 100644 --- a/SpotifyAPI.Web/Models/IPaginatable.cs +++ b/SpotifyAPI.Web/Models/IPaginatable.cs @@ -5,17 +5,17 @@ namespace SpotifyAPI.Web public interface IPaginatable { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")] - string Next { get; set; } + string? Next { get; set; } - List Items { get; set; } + List? Items { get; set; } } public interface IPaginatable { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")] - string Next { get; set; } + string? Next { get; set; } - List Items { get; set; } + List? Items { get; set; } } } diff --git a/SpotifyAPI.Web/Models/Request/RequestParams.cs b/SpotifyAPI.Web/Models/Request/RequestParams.cs index bb7589ed..d5cc3319 100644 --- a/SpotifyAPI.Web/Models/Request/RequestParams.cs +++ b/SpotifyAPI.Web/Models/Request/RequestParams.cs @@ -122,7 +122,8 @@ namespace SpotifyAPI.Web { if (StringAttribute.GetValue(enumType, enumVal, out var stringVal)) { - valueList.Add(stringVal); + // .netstandard2.0 requires ! + valueList.Add(stringVal!); } } } @@ -131,7 +132,8 @@ namespace SpotifyAPI.Web { if (StringAttribute.GetValue(enumType, valueAsEnum, out var stringVal)) { - valueList.Add(stringVal); + // .netstandard2.0 requires ! + valueList.Add(stringVal!); } } queryParams.Add(attribute.Key ?? prop.Name, string.Join(",", valueList)); diff --git a/SpotifyAPI.Web/Models/Response/CursorPaging.cs b/SpotifyAPI.Web/Models/Response/CursorPaging.cs index f56ef97f..262c1fbe 100644 --- a/SpotifyAPI.Web/Models/Response/CursorPaging.cs +++ b/SpotifyAPI.Web/Models/Response/CursorPaging.cs @@ -5,9 +5,9 @@ namespace SpotifyAPI.Web public class CursorPaging : IPaginatable { public string Href { get; set; } = default!; - public List Items { get; set; } = default!; + public List? Items { get; set; } = default!; public int Limit { get; set; } - public string Next { get; set; } = default!; + public string? Next { get; set; } = default!; public Cursor Cursors { get; set; } = default!; public int Total { get; set; } } @@ -15,9 +15,9 @@ namespace SpotifyAPI.Web public class CursorPaging : IPaginatable { public string Href { get; set; } = default!; - public List Items { get; set; } = default!; + public List? Items { get; set; } = default!; public int Limit { get; set; } - public string Next { get; set; } = default!; + public string? Next { get; set; } = default!; public Cursor Cursors { get; set; } = default!; public int Total { get; set; } } diff --git a/SpotifyAPI.Web/Models/Response/FullPlaylist.cs b/SpotifyAPI.Web/Models/Response/FullPlaylist.cs index fa6945b8..01e02b7d 100644 --- a/SpotifyAPI.Web/Models/Response/FullPlaylist.cs +++ b/SpotifyAPI.Web/Models/Response/FullPlaylist.cs @@ -3,23 +3,23 @@ namespace SpotifyAPI.Web { public class FullPlaylist { - public bool Collaborative { get; set; } - public Dictionary ExternalUrls { get; set; } = default!; - public string Href { get; set; } = default!; - public string Id { get; set; } = default!; - public List Images { get; set; } = default!; - public string Name { get; set; } = default!; - public PublicUser Owner { get; set; } = default!; - public bool Public { get; set; } - public string SnapshotId { get; set; } = default!; + public bool? Collaborative { get; set; } + public Dictionary? ExternalUrls { get; set; } = default!; + public string? Href { get; set; } = default!; + public string? Id { get; set; } = default!; + public List? Images { get; set; } = default!; + public string? Name { get; set; } = default!; + public PublicUser? Owner { get; set; } = default!; + public bool? Public { get; set; } + public string? SnapshotId { get; set; } = default!; /// /// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode /// /// - public Paging> Tracks { get; set; } = default!; - public string Type { get; set; } = default!; - public string Uri { get; set; } = default!; + public Paging>? Tracks { get; set; } = default!; + public string? Type { get; set; } = default!; + public string? Uri { get; set; } = default!; } } diff --git a/SpotifyAPI.Web/Models/Response/Paging.cs b/SpotifyAPI.Web/Models/Response/Paging.cs index 296a82ac..a03756c4 100644 --- a/SpotifyAPI.Web/Models/Response/Paging.cs +++ b/SpotifyAPI.Web/Models/Response/Paging.cs @@ -4,24 +4,24 @@ namespace SpotifyAPI.Web { public class Paging : IPaginatable { - public string Href { get; set; } = default!; - public List Items { get; set; } = default!; - public int Limit { get; set; } - public string Next { get; set; } = default!; - public int Offset { get; set; } - public string Previous { get; set; } = default!; - public int Total { get; set; } + public string? Href { get; set; } = default!; + public List? Items { get; set; } = default!; + public int? Limit { get; set; } = default!; + public string? Next { get; set; } = default!; + public int? Offset { get; set; } = default!; + public string? Previous { get; set; } = default!; + public int? Total { get; set; } = default!; } public class Paging : IPaginatable { - public string Href { get; set; } = default!; - public List Items { get; set; } = default!; - public int Limit { get; set; } - public string Next { get; set; } = default!; - public int Offset { get; set; } - public string Previous { get; set; } = default!; - public int Total { get; set; } + public string? Href { get; set; } = default!; + public List? Items { get; set; } = default!; + public int? Limit { get; set; } = default!; + public string? Next { get; set; } = default!; + public int? Offset { get; set; } = default!; + public string? Previous { get; set; } = default!; + public int? Total { get; set; } = default!; } }