c# 分页 PaginatedList<TResult>

2021-01-21 04:15

阅读:532

标签:ace   rev   extension   pre   using   page   selector   index   space   

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 
 5 namespace Microestc.PaginatedList
 6 {
 7     public class PaginatedList : List 8     {
 9         public PaginatedList() : base() { }
10 
11         public PaginatedList(IEnumerable items, int totalCount, int pageIndex, int pageSize) : base(items)
12         {
13             TotalCount = totalCount;
14             PageCount = (totalCount + pageSize - 1) / pageSize;
15             PageIndex = pageIndex;
16             PageSize = pageSize;
17             HasPrev = pageIndex > 1;
18             HasNext = pageIndex  PageCount;
19         }
20 
21         public virtual int TotalCount { get; private set; }
22 
23         public virtual int PageCount { get; private set; }
24 
25         public virtual int PageIndex { get; private set; }
26 
27         public virtual int PageSize { get; private set; }
28 
29         public virtual bool HasPrev { get; private set; }
30 
31         public virtual bool HasNext { get; private set; }
32     }
33 
34     public static class PaginatedListExtensions
35     {
36         public static PaginatedList PaginatedList(this IEnumerable source, int pageIndex, int pageSize)
37         {
38             var count = source.Count();
39             var items = source.Skip((pageIndex - 1) * pageSize).Take(pageSize);
40             return new PaginatedList(items, count, pageIndex, pageSize);
41         }
42 
43         public static PaginatedList PaginatedList(this IEnumerable source, Func selector, int pageIndex, int pageSize)
44         {
45             var count = source.Count();
46             var items = source.Skip((pageIndex - 1) * pageSize).Take(pageSize).Select(selector);
47             return new PaginatedList(items, count, pageIndex, pageSize);
48         }
49     }
50 }

c# 分页 PaginatedList

标签:ace   rev   extension   pre   using   page   selector   index   space   

原文地址:https://www.cnblogs.com/microestc/p/12113502.html


评论


亲,登录后才可以留言!