public class Pager<T> where T : new()
{
private IEnumerable<T> _all;
private IEnumerable<T> _current;
public Pager()
: this(, )
{ }
public Pager(int pageIndex, int pageSize)
: this(null, pageIndex, pageSize)
{
}
public Pager(IEnumerable<T> items, int pageIndex = , int pageSize = )
{
PageIndex = pageIndex;
PageSize = pageSize;
if (items != null)
{
_all = items;
var count = _all.Count();
PageCount = count % pageSize > ? (count / pageSize + ) : count / pageSize;
}
} public int PageIndex { get; set; }
public int PageSize { get; private set; }
public int PageCount
{
get;
set;
} public IEnumerable<T> Current
{
get
{
if (_all != null) _current = _all.Skip(PageIndex * PageSize).Take(PageSize);
return _current;
}
set { _current = value; }
} }
this pager supports dual methods, memory pagination or direct usage.