zoukankan      html  css  js  c++  java
  • c# 分页 PaginatedList<TResult>

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 
     5 namespace Microestc.PaginatedList
     6 {
     7     public class PaginatedList<TResult> : List<TResult>
     8     {
     9         public PaginatedList() : base() { }
    10 
    11         public PaginatedList(IEnumerable<TResult> 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<TResult> PaginatedList<TResult>(this IEnumerable<TResult> 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<TResult>(items, count, pageIndex, pageSize);
    41         }
    42 
    43         public static PaginatedList<TResult> PaginatedList<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> 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<TResult>(items, count, pageIndex, pageSize);
    48         }
    49     }
    50 }
  • 相关阅读:
    Php扩展--protocolbuffers消息打包
    Php扩展--seasLog日志扩展安装
    PHP系统编程--03.PHP进程信号处理
    PHP系统编程--01.多进程与多线程
    PHP系统编程--02.PHP守护进程化
    linux shell 之if-------用if做判断
    Connection:Keep-alive
    Http报头Accept与Content-Type的区别
    json解析
    JSON-lib框架,转换JSON、XML不再困难
  • 原文地址:https://www.cnblogs.com/microestc/p/12113502.html
Copyright © 2011-2022 走看看