新文章 网摘 文章 随笔 日记

改进的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;
            }
        }
    }

posted @ 2019-12-04 11:07  岭南春  阅读(215)  评论(0编辑  收藏  举报