Sakura.AspNetCore.Extensions/Sakura.AspNetCore.Mvc.PagedList/Internal/DefaultPagerListGenerator.cs
/// <summary>
///     Core method for generating normal pager items according to the page information.
/// </summary>
/// <param name="currentPage">The current page number.</param>
/// <param name="totalPage">The count of total pages.</param>
/// <param name="expandForCurrentPage">How many pages should be expanded for current page.</param>
/// <param name="expandForEnding">How many pages should be expanded for ending.</param>
/// <returns></returns>
Core method for generating normal pager items according to the page information.
Core method for generating normal pager items according to the page information .
private static IEnumerable<PagerItem> GeneratePagerNormalItems(int currentPage, int totalPage,
			int expandForCurrentPage,
			int expandForEnding)
		{
			var pageNumberList = new SortedSet<int> {currentPage};
			for (var i = 1; i <= expandForCurrentPage; i++)
			{
				pageNumberList.Add(currentPage + i);
				pageNumberList.Add(currentPage - i);
			}
			for (var i = 1; i <= expandForEnding; i++)
			{
				pageNumberList.Add(i);
				pageNumberList.Add(totalPage + 1 - i);
			}
			pageNumberList.RemoveWhere(i => i < 1 || i > totalPage);
			var lastPageNumber = 0;
			foreach (var i in pageNumberList)
			{
				if (i - lastPageNumber > 1)
					yield return new PagerItem
					{
						ItemType = PagerItemType.Omitted,
						PageNumber = -1
					};
				yield return new PagerItem
				{
					ItemType = i == currentPage ? PagerItemType.Current : PagerItemType.Normal,
					PageNumber = i
				};
				lastPageNumber = i;
			}
			if (lastPageNumber < totalPage)
				yield return new PagerItem
				{
					ItemType = PagerItemType.Omitted,
					PageNumber = -1
				};
		}
private static IEnumerable < PagerItem > GeneratePagerNormalItems ( int currentPage , int totalPage , int expandForCurrentPage , int expandForEnding ) { var pageNumberList = new SortedSet < int > { currentPage } ; for ( var i = 1 ; i <= expandForCurrentPage ; i ++ ) { pageNumberList . Add ( currentPage + i ) ; pageNumberList . Add ( currentPage - i ) ; } for ( var i = 1 ; i <= expandForEnding ; i ++ ) { pageNumberList . Add ( i ) ; pageNumberList . Add ( totalPage + 1 - i ) ; } pageNumberList . RemoveWhere ( i => i < 1 || i > totalPage ) ; var lastPageNumber = 0 ; foreach ( var i in pageNumberList ) { if ( i - lastPageNumber > 1 ) yield return new PagerItem { ItemType = PagerItemType . Omitted , PageNumber = - 1 } ; yield return new PagerItem { ItemType = i == currentPage ? PagerItemType . Current : PagerItemType . Normal , PageNumber = i } ; lastPageNumber = i ; } if ( lastPageNumber < totalPage ) yield return new PagerItem { ItemType = PagerItemType . Omitted , PageNumber = - 1 } ; }
Core method for generating normal pager items according to the page information.
Core method for generating normal pager items according to the page information .
// Expand for current page // Expand for ending // Remove invalid items // Skipped some item // is current page // Set last page // last page omit handling
None
currentPage
int
The current page number.
The current page number .
totalPage
int
The count of total pages.
The count of total pages .
expandForCurrentPage
int
None
expandForEnding
int
None