dncuug / X.PagedList

Library for easily paging through any IEnumerable/IQueryable in ASP.NET
https://nuget.org/packages/X.PagedList
MIT License
886 stars 213 forks source link

X.PagedList.Mvc.Core: Improve nullable handling for generatePageUrl #273

Closed adschmu closed 2 months ago

adschmu commented 2 months ago

We only ever use the generatePageUrl argument (in various places) to set HTML attribute values with TagBuilder.Attributes.Add().

The latter specifically accepts nullable strings for the value. Thus, this commits adjusts the return type of the Func<int, string> for generatePageUrl to be nullable as well, i.e. to Func<int, string?>, for all affected cases.

This removes nullable warnings for actual use cases like the following:

@Html.PagedListPager(someModel, page => Url.Action(...), ...)

Here, Url.Action returns string? and thus creates a nullable warning CS8603 with the implementation before this commit. Since TagBuilder.Attributes.Add() allows string?, though, we can be more permissive here and do so with this commit.


This has been found while testing 10.0.0-pre