改进的PageView
public class PageView<T>
{
private ColumnTitle[] _columnTitles;
public int RecordCount { get; }
public IList<T> Items { get; }
public int PageIndex { get; }
public int PageSize { get; }
public int PageCount { get; }
public PageView(int pageSize, int pageIndex, IList<T> items, int recordCount)
{
Items = items ?? new List<T>();
if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize));
if (pageIndex <= 0) throw new ArgumentOutOfRangeException(nameof(pageIndex));
if (recordCount < 0) throw new ArgumentOutOfRangeException(nameof(recordCount));
RecordCount = recordCount;
PageCount = Convert.ToInt32(Math.Ceiling(recordCount * 1.0 / pageSize));
PageIndex = pageIndex > PageCount ? PageCount : pageIndex;
PageSize = pageSize;
}
/// <summary>
/// 列标题
/// </summary>
public ColumnTitle[] ColumnTitles
{
get
{
if (_columnTitles == null)
{
var type = typeof(T);
_columnTitles = type.GetColumnTitle();
}
return _columnTitles;
}
}
}