/// <summary> /// Initialize a new instance with specified information. /// </summary> /// <param name="source">The data source to be paging.</param> /// <param name="pageSize">The size of each page.</param> /// <param name="pageIndex">The index of the current page, start from 1.</param> /// <param name="cacheOptions">Additional cacheOptions for the paged list.</param> protected DynamicPagedListBase(TCollection source, int pageSize, int pageIndex = 1, DynamicPagedListCacheOptions cacheOptions = null) { // Default parameters var defaultOptions = new DynamicPagedListCacheOptions { CurrentPageCacheMode = CacheMode.Manual, TotalCountCacheMode = CacheMode.Manual }; // Merge cacheOptions cacheOptions = cacheOptions ?? defaultOptions; // Initialize the data source Source = source != null ? source : throw new ArgumentNullException(nameof(source)); // Set Paging information PageSize = pageSize; PageIndex = pageIndex; // Caching total count for first time TotalCountCacheInternal = new Cacheable <int>(GetTotalCount, cacheMode: cacheOptions.TotalCountCacheMode); // Caching current page for first time CurrentPageCacheInternal = new Cacheable <TCollection>(GetCurrentPage, CacheData, cacheOptions.CurrentPageCacheMode); // Set initialized flag IsInitialized = true; }
/// <summary> /// Initialize a new instance with specified information. /// </summary> /// <param name="source">The data source to be paging.</param> /// <param name="pageSize">The size of each page.</param> /// <param name="pageIndex">The index of the current page, start from 1.</param> /// <param name="cacheOptions">Additional cacheOptions for the paged list.</param> public AsyncPagedList(IAsyncEnumerable <T> source, int pageSize, int pageIndex = 1, DynamicPagedListCacheOptions cacheOptions = null) { // Exception handling if (source == null) { throw new ArgumentNullException(nameof(source)); } // Default parameters var defaultOptions = new DynamicPagedListCacheOptions { CurrentPageCacheMode = CacheMode.Manual, TotalCountCacheMode = CacheMode.Manual }; // Merge cacheOptions cacheOptions = cacheOptions ?? defaultOptions; // Initialize the data source Source = source; // Set Paging information PageSize = pageSize; PageIndex = pageIndex; // Caching total count for first time TotalCountCacheInternal = new AsyncCacheable <Task <int> >(GetTotalCountAsync, cacheMode: cacheOptions.TotalCountCacheMode); // Caching current page for first time CurrentPageCacheInternal = new AsyncCacheable <IAsyncEnumerable <T> >(GetCurrentPageAsync, CacheDataAsync, cacheOptions.CurrentPageCacheMode); // Set initialized flag IsInitialized = true; }
/// <summary> /// Initialize a new instance with specified information. /// </summary> /// <param name="source">The data source to be paging.</param> /// <param name="pageSize">The size of each page.</param> /// <param name="pageIndex">The index of the current page. Page index starts from 1.</param> /// <param name="cacheOptions">Additional options for the paged list.</param> public DynamicPagedList(IEnumerable <T> source, int pageSize, int pageIndex = 1, DynamicPagedListCacheOptions cacheOptions = null) : base(source, pageSize, pageIndex, cacheOptions) { }
/// <summary> /// Convert <see cref="IQueryable{T}" /> object into a <see cref="DynamicQueryablePagedList{T}" /> object. /// </summary> /// <typeparam name="T">The element type in the data source.</typeparam> /// <param name="source">The source <see cref="IQueryable{T}" /> object to be converting.</param> /// <param name="pageSize">The size of each page.</param> /// <param name="pageIndex">The index of the current page. Page index starts from 1.</param> /// <param name="cacheOptions">Options for the paged list.</param> /// <returns>A <see cref="DynamicQueryablePagedList{T}" /> object created by paging the <paramref name="source" /> object.</returns> public static DynamicQueryablePagedList <T> ToDynamicPagedList <T>(this IQueryable <T> source, int pageSize, int pageIndex = 1, DynamicPagedListCacheOptions cacheOptions = null) => new DynamicQueryablePagedList <T>(source, pageSize, pageIndex, cacheOptions);
/// <summary> /// Convert <see cref="IEnumerable{T}" /> object into a <see cref="DynamicPagedList{T}" /> object. /// </summary> /// <typeparam name="T">The element type in the data source.</typeparam> /// <param name="source">The source <see cref="IEnumerable{T}" /> object to be converting.</param> /// <param name="pageSize">The size of each page.</param> /// <param name="pageIndex">The index of the current page. Page index starts from 1.</param> /// <param name="cacheOptions">Options for the paged list.</param> /// <returns>A <see cref="DynamicPagedList{T}" /> object created by paging the <paramref name="source" /> object.</returns> public static DynamicPagedList <T> ToDynamicPagedList <T>(this IEnumerable <T> source, int pageSize, int pageIndex = 1, DynamicPagedListCacheOptions cacheOptions = null) { return(new DynamicPagedList <T>(source, pageSize, pageIndex, cacheOptions)); }