/// <summary>
        /// Converts IEnumerable to a Page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pageIndex">Index of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <param name="itemCount">Total item count of IEnumerable</param>
        /// <param name="prePaged">Is the IEnumerable already prepaged. If so the IEnumerable will not be paged anymore.</param>
        /// <returns></returns>
        public static Page <T> ToPage <T>(this IEnumerable <T> source, int pageIndex, int pageSize, int itemCount, bool prePaged = false)
        {
            Validator.Validate(pageIndex, pageSize);

            var pd = new PageDefinition(pageIndex, pageSize, itemCount);

            return(prePaged || pd.ItemCount < 1
                  ? Page <T> .FromEnumerable(source, pd)
                  : Page <T> .FromEnumerable(source.Skip(pd.SkipIndex).Take(pd.PageSize), pd));
        }
        /// <summary>
        /// Converts IEnumerable to a Page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pagerFilter"><see cref="IPagerFilter"/></param>
        /// <returns></returns>
        public static Page <T> ToPage <T>(this IEnumerable <T> source, IPagerFilter pagerFilter)
        {
            Validator.Validate(pagerFilter);

            var pd = new PageDefinition(pagerFilter, source.Count());

            return(pd.ItemCount < 1
                  ? Page <T> .FromEnumerable(source, pd)
                  : Page <T> .FromEnumerable(source.Skip(pd.SkipIndex).Take(pd.PageSize), pd));
        }
        /// <summary>
        /// Converts asynchronous IEnumerable to a Page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pagerFilter"><see cref="IPagerFilter"/></param>
        /// <param name="itemCount">Total item count of IEnumerable</param>
        /// <param name="prePaged">Is the IEnumerable already prepaged. If so the IEnumerable will not be paged anymore.</param>
        /// <returns></returns>
        public static async Task <Page <T> > ToPageAsync <T>(this IEnumerable <T> source, IPagerFilter pagerFilter, int itemCount, bool prePaged = false)
        {
            Validator.Validate(pagerFilter);

            var pd = new PageDefinition(pagerFilter, itemCount);

            return(prePaged || pd.ItemCount < 1
                  ? await Task.Run(() => Page <T> .FromEnumerable(source, pd)).ConfigureAwait(false)
                  : await Task.Run(() => Page <T> .FromEnumerable(source.Skip(pd.SkipIndex).Take(pd.PageSize), pd)).ConfigureAwait(false));
        }
        /// <summary>
        /// Converts asynchronous IEnumerable to a Page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pageIndex">Index of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <returns></returns>
        public static async Task <Page <T> > ToPageAsync <T>(this IEnumerable <T> source, int pageIndex, int pageSize)
        {
            Validator.Validate(pageIndex, pageSize);

            var pd = new PageDefinition(pageIndex, pageSize, source.Count());

            return(pd.ItemCount < 1
                  ? await Task.Run(() => Page <T> .FromEnumerable(source, pd)).ConfigureAwait(false)
                  : await Task.Run(() => Page <T> .FromEnumerable(source.Skip(pd.SkipIndex).Take(pd.PageSize), pd)).ConfigureAwait(false));
        }
示例#5
0
        /// <summary>
        /// Converts IQueryable to a Page
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="pageIndex">Index of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <returns></returns>
        public static Page <T> ToPage <T>(this IQueryable <T> source, int pageIndex, int pageSize)
        {
            Validator.Validate(pageIndex, pageSize);

            var pd = new PageDefinition(pageIndex, pageSize, source.Count());

            return(pd.ItemCount < 1
                  ? Page <T> .FromEnumerable(source, pd)
                  : Page <T> .FromEnumerable(source.Skip(pd.SkipIndex).Take(pd.PageSize), pd));
        }
示例#6
0
        /// <summary>
        /// Converts a collection to a specific Page
        /// </summary>
        /// <param name="source">the elements of the current page</param>
        /// <param name="definitions">the definition of the current page and its position in the original list</param>
        internal Page(IEnumerable <T> source, PageDefinition definitions)
        {
            if (source != null && definitions.ItemCount > 0)
            {
                var arrSource = source.ToArray();

                _list = arrSource.Any()
                    ? new List <T>(arrSource)
                    : new List <T>();
            }
            else
            {
                _list = new List <T>();
            }

            CurrentPageIndex = definitions.PageIndex;
            TotalPageCount   = definitions.PageCount;
            PageSize         = definitions.PageSize;
            TotalItemCount   = definitions.ItemCount;
        }
示例#7
0
        /// <summary>
        /// Converts a collection to a specific Page
        /// </summary>
        /// <param name="source">the elements of the current page</param>
        /// <param name="definitions">the definition of the current page and its position in the original list</param>
        internal static Page <T> FromEnumerable(IEnumerable <T> source, PageDefinition definitions)
        {
            var page = new Page <T>();

            if (source != null && definitions.ItemCount > 0)
            {
                var arrSource = source.ToArray();

                page._list = arrSource.Any()
                    ? new List <T>(arrSource)
                    : new List <T>();
            }
            else
            {
                page._list = new List <T>();
            }

            page.CurrentPageIndex = definitions.PageIndex;
            page.TotalPageCount   = definitions.PageCount;
            page.PageSize         = definitions.PageSize;
            page.TotalItemCount   = definitions.ItemCount;

            return(page);
        }
示例#8
0
        /// <summary>
        /// Converts a collection to a specific Page
        /// </summary>
        /// <param name="source">the elements of the current page</param>
        /// <param name="pageIndex">The currently selected page in the original list</param>
        /// <param name="pageSize">Size of an individual page</param>
        /// <param name="itemCount">Total item count in the original list</param>
        public Page(IEnumerable <T> source, int pageIndex, int pageSize, int itemCount)
        {
            Validator.Validate(pageIndex, pageSize);

            var definitions = new PageDefinition(pageIndex, pageSize, itemCount);

            if (source != null && definitions.ItemCount > 0)
            {
                var arrSource = source.ToArray();

                _list = arrSource.Any()
                    ? new List <T>(arrSource)
                    : new List <T>();
            }
            else
            {
                _list = new List <T>();
            }

            CurrentPageIndex = definitions.PageIndex;
            TotalPageCount   = definitions.PageCount;
            PageSize         = definitions.PageSize;
            TotalItemCount   = definitions.ItemCount;
        }