大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。
废话不说只有代码:
1 using System.Linq; 2 using System.Collections.Generic; 3 4 namespace CommonLibrary 5 { 6 public class PagedList<T> : List<T> 7 { 8 #region Properties 9 10 public int PageIndex { get; private set; } 11 12 public int PageSize { get; private set; } 13 14 public int TotalCount { get; private set; } 15 16 public int TotalPages { get; private set; } 17 18 public bool HasPreviousPage 19 { 20 get { return (PageIndex > 0); } 21 } 22 public bool HasNextPage 23 { 24 get { return (PageIndex + 1 < TotalPages); } 25 } 26 27 #endregion 28 //http://www.cnblogs.com/roucheng/ 29 #region Constructors 30 31 public PagedList(IQueryable<T> source, int pageIndex, int pageSize) 32 { 33 if (source == null || source.Count() < 1) 34 throw new System.ArgumentNullException("source"); 35 36 int total = source.Count(); 37 this.TotalCount = total; 38 this.TotalPages = total / pageSize; 39 40 if (total % pageSize > 0) 41 TotalPages++; 42 43 this.PageSize = pageSize; 44 this.PageIndex = pageIndex; 45 this.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList()); 46 } 47 48 public PagedList(IList<T> source, int pageIndex, int pageSize) 49 { 50 if (source == null || source.Count() < 1) 51 throw new System.ArgumentNullException("source"); 52 53 TotalCount = source.Count(); 54 TotalPages = TotalCount / pageSize; 55 56 if (TotalCount % pageSize > 0) 57 TotalPages++; 58 59 this.PageSize = pageSize; 60 this.PageIndex = pageIndex; 61 this.AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList()); 62 } 63 64 public PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount) 65 { 66 if (source == null || source.Count() < 1) 67 throw new System.ArgumentNullException("source"); 68 69 TotalCount = totalCount; 70 TotalPages = TotalCount / pageSize; 71 72 if (TotalCount % pageSize > 0) 73 TotalPages++; 74 75 this.PageSize = pageSize; 76 this.PageIndex = pageIndex; 77 this.AddRange(source); 78 } 79 80 #endregion 81 } 82 }
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/120768.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...