Skip to content

Commit

Permalink
Remove inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy committed Oct 12, 2024
1 parent 60a6fc3 commit 70c3214
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions src/X.PagedList/BasePagedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,68 @@ namespace X.PagedList;
/// <seealso cref = "IPagedList{T}" />
/// <seealso cref = "List{T}" />
[PublicAPI]
public abstract class BasePagedList<T> : PagedListMetaData, IPagedList<T>
public abstract class BasePagedList<T> : IPagedList<T>
{
protected List<T> Subset = new();

public const int DefaultPageSize = 100;

/// <summary>
/// Total number of subsets within the superset.
/// </summary>
public int PageCount { get; protected set; }

/// <summary>
/// Total number of objects contained within the superset.
/// </summary>
public int TotalItemCount { get; protected set; }

/// <summary>
/// One-based index of this subset within the superset, zero if the superset is empty.
/// </summary>
public int PageNumber { get; protected set; }

/// <summary>
/// Maximum size any individual subset.
/// </summary>
public int PageSize { get; protected set; }

/// <summary>
/// Returns true if the superset is not empty and PageNumber is less than or equal to PageCount and this
/// is NOT the first subset within the superset.
/// </summary>
public bool HasPreviousPage { get; protected set; }

/// <summary>
/// Returns true if the superset is not empty and PageNumber is less than or equal to PageCount and this
/// is NOT the last subset within the superset.
/// </summary>
public bool HasNextPage { get; protected set; }

/// <summary>
/// Returns true if the superset is not empty and PageNumber is less than or equal to PageCount and this is
/// the first subset within the superset.
/// </summary>
public bool IsFirstPage { get; protected set; }

/// <summary>
/// Returns true if the superset is not empty and PageNumber is less than or equal to PageCount and this is
/// the last subset within the superset.
/// </summary>
public bool IsLastPage { get; protected set; }

/// <summary>
/// One-based index of the first item in the paged subset, zero if the superset is empty or PageNumber
/// is greater than PageCount.
/// </summary>
public int FirstItemOnPage { get; protected set; }

/// <summary>
/// One-based index of the last item in the paged subset, zero if the superset is empty or PageNumber is
/// greater than PageCount.
/// </summary>
public int LastItemOnPage { get; protected set; }

/// <summary>
/// Parameterless constructor.
/// </summary>
Expand Down Expand Up @@ -51,7 +107,8 @@ protected internal BasePagedList(int pageNumber, int pageSize, int totalItemCoun

if (totalItemCount < 0)
{
throw new ArgumentOutOfRangeException($"totalItemCount = {totalItemCount}. TotalItemCount cannot be less than 0.");
throw new ArgumentOutOfRangeException(
$"totalItemCount = {totalItemCount}. TotalItemCount cannot be less than 0.");
}

// set source to blank list if superset is null to prevent exceptions
Expand Down Expand Up @@ -116,4 +173,4 @@ IEnumerator IEnumerable.GetEnumerator()
///<returns>A non-enumerable copy of this paged list.</returns>
[Obsolete("This method will be removed in future versions")]
public PagedListMetaData GetMetaData() => new(this);
}
}

0 comments on commit 70c3214

Please sign in to comment.