You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB
C#

1 month ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SlnMesnac.RfidUpload.Common
{
public class ListPage<T>
{
public int TotalPage { get; set; }
public int Total { get; set; }
public int PageSize { get; set; } = 50;
public List<T> Ls { get; set; }
public ListPage(IEnumerable<T> ls, int pageSize = 500)
{
if (!(ls is T[] objArray))
objArray = ls.ToArray<T>();
T[] source = objArray;
this.Ls = ((IEnumerable<T>)source).ToList<T>();
this.Total = ((IEnumerable<T>)source).Count<T>();
this.PageSize = pageSize;
this.TotalPage = (((IEnumerable<T>)source).Count<T>() + this.PageSize - 1) / this.PageSize;
}
public IEnumerable<IEnumerable<T>> GetPage()
{
List<IEnumerable<T>> page = new List<IEnumerable<T>>();
for (int index = 0; index < this.TotalPage; ++index)
{
IEnumerable<T> objs = this.Ls.Skip<T>(this.PageSize * index).Take<T>(this.PageSize);
page.Add(objs);
}
return (IEnumerable<IEnumerable<T>>)page;
}
}
}