Sakura.AspNetCore.Extensions/Sakura.AspNetCore.PagedList/PagedListCreationHelper.cs
/// <summary>
///     Core method used to generate an instance of <see cref="PagedList{TSource,TElement}" />.
/// </summary>
/// <typeparam name="TSource">The source type.</typeparam>
/// <typeparam name="TElement">The element type in the paged list.</typeparam>
/// <param name="source">The source to be paged.</param>
/// <param name="pageSize">The size of page.</param>
/// <param name="pageIndex">The index of the currnet page.</param>
/// <param name="pageFunc">A paging function that skip some items, and then take some items, finally convert to a list.</param>
/// <param name="countFunc">A function to count the items in the source.</param>
/// <returns>A <see cref="PagedList{TSource,TElement}" /> object created by paging the <paramref name="source" /> object.</returns>
Core method used to generate an instance of .
Core method used to generate an instance of .
private static PagedList<TSource, TElement> CreatePagedListCore<TSource, TElement>([NotNull] this TSource source,
			int pageSize, int pageIndex, Func<TSource, int, int, IList<TElement>> pageFunc, Func<TSource, int> countFunc)
		{
			if (source == null)
				throw new ArgumentNullException(nameof(source));
			if (pageSize <= 0)
				throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive.");
			if (pageIndex <= 0)
				throw new ArgumentOutOfRangeException(nameof(pageIndex), pageIndex, "The page index must be positive.");
			var skipValue = pageSize * (pageIndex - 1);
			var takeValue = pageSize;
			var currentPage = pageFunc(source, skipValue, takeValue);
			var totalCount = countFunc(source);
			var totalPage = (totalCount - 1) / pageSize + 1;
			return new PagedList<TSource, TElement>(currentPage, source, pageSize, pageIndex, totalCount, totalPage);
		}
private static PagedList < TSource , TElement > CreatePagedListCore < TSource , TElement > ( [ NotNull ] this TSource source , int pageSize , int pageIndex , Func < TSource , int , int , IList < TElement > > pageFunc , Func < TSource , int > countFunc ) { if ( source == null ) throw new ArgumentNullException ( nameof ( source ) ) ; if ( pageSize <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( pageSize ) , pageSize , " " ) ; if ( pageIndex <= 0 ) throw new ArgumentOutOfRangeException ( nameof ( pageIndex ) , pageIndex , " " ) ; var skipValue = pageSize * ( pageIndex - 1 ) ; var takeValue = pageSize ; var currentPage = pageFunc ( source , skipValue , takeValue ) ; var totalCount = countFunc ( source ) ; var totalPage = ( totalCount - 1 ) / pageSize + 1 ; return new PagedList < TSource , TElement > ( currentPage , source , pageSize , pageIndex , totalCount , totalPage ) ; }
Core method used to generate an instance of .
Core method used to generate an instance of .
A  object created by paging the  object.
A object created by paging the object .
this
[NotNull]
pageSize
int
The size of page.
The size of page .
pageIndex
int
The index of the currnet page.
The index of the currnet page .
pageFunc
Func<TSource, int, int, IList<TElement>>
A paging function that skip some items, and then take some items, finally convert to a list.
A paging function that skip some items and then take some items finally convert to a list .
countFunc
Func<TSource, int>
A function to count the items in the source.
A function to count the items in the source .
source
The source to be paged.
The source to be paged .
typeparam
The source type.
The source type .
typeparam
The element type in the paged list.
The element type in the paged list .