Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

PagedList.cs

namespace Nop.Core;

/// 
/// Paged list
/// 
/// T
[Serializable]
public partial class PagedList : List, IPagedList
{
    /// 
    /// Ctor
    /// 
    /// source
    /// Page index
    /// Page size
    /// Total count
    public PagedList(IList source, int pageIndex, int pageSize, int? totalCount = null)
    {
        //min allowed page size is 1
        pageSize = Math.Max(pageSize, 1);

        TotalCount = totalCount ?? source.Count;
        TotalPages = TotalCount / pageSize;

        if (TotalCount % pageSize > 0)
            TotalPages++;

        PageSize = pageSize;
        PageIndex = pageIndex;
        AddRange(totalCount != null ? source : source.Skip(pageIndex * pageSize).Take(pageSize));
    }

    /// 
    /// Page index
    /// 
    public int PageIndex { get; }

    /// 
    /// Page size
    /// 
    public int PageSize { get; }

    /// 
    /// Total count
    /// 
    public int TotalCount { get; }

    /// 
    /// Total pages
    /// 
    public int TotalPages { get; }

    /// 
    /// Has previous page
    /// 
    public bool HasPreviousPage => PageIndex > 0;

    /// 
    /// Has next page
    /// 
    public bool HasNextPage => PageIndex + 1 < TotalPages;
}