Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 12 #283

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9f2eb42
Update version
a-gubskiy Jul 13, 2024
2d91bc0
Remove PagedListMetaData
a-gubskiy Jul 13, 2024
766aac0
Cleanup code
a-gubskiy Jul 13, 2024
57a2b87
Simplify properties logic
a-gubskiy Jul 13, 2024
66250f6
Update version
a-gubskiy Jul 13, 2024
6ccaed1
Remove PagedListMetaData
a-gubskiy Jul 13, 2024
3bec1d4
Make filed calculated
a-gubskiy Jul 13, 2024
f4829f8
Update PageCount property
a-gubskiy Jul 13, 2024
869812b
Remove PagedListMetaData
a-gubskiy Jul 13, 2024
676e226
Removed GetMetaData
a-gubskiy Jul 13, 2024
e43c33d
Update version
a-gubskiy Jul 13, 2024
8bf0c32
Fix merge issues
a-gubskiy Jul 13, 2024
ec4735b
Fix merge issues
a-gubskiy Jul 13, 2024
155d9eb
Cleanup code
a-gubskiy Jul 13, 2024
6242066
Cleanup code
a-gubskiy Jul 13, 2024
4b9be4c
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Jul 13, 2024
32b1f3e
Fix merge issue
a-gubskiy Jul 13, 2024
ef87d1b
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Jul 13, 2024
3daf8b6
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Jul 13, 2024
5325ba1
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Aug 1, 2024
758a863
Fix project configuration
a-gubskiy Aug 1, 2024
baf82c2
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Aug 1, 2024
a1f39b6
Merge remote-tracking branch 'origin/294-cleanup-unused-projects' int…
a-gubskiy Sep 20, 2024
bd8877c
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Sep 20, 2024
c8fee69
Update workflow
a-gubskiy Sep 20, 2024
8a0df12
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Sep 20, 2024
d24514f
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Sep 20, 2024
79d0c00
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Sep 20, 2024
c12513d
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Oct 12, 2024
1ffe903
Fix conflicts
a-gubskiy Oct 12, 2024
c27f468
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Oct 12, 2024
ea1b954
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Oct 12, 2024
8548719
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Oct 12, 2024
b754e59
Merge remote-tracking branch 'origin/master' into version-11
a-gubskiy Oct 12, 2024
1725e03
Merge remote-tracking branch 'origin/version-11' into version-12
a-gubskiy Oct 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/Example.DAL/Animal.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;

namespace Example.DAL;
namespace Example.DAL;

public partial class Animal
{
Expand Down
4 changes: 1 addition & 3 deletions examples/Example.DAL/DatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Example.DAL;

Expand Down
5 changes: 1 addition & 4 deletions examples/Example.DAL/User.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;

namespace Example.DAL;
namespace Example.DAL;

public partial class User
{
Expand Down
8 changes: 4 additions & 4 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<Copyright>Andrew Gubskiy © 2024</Copyright>
<Company>Ukrainian .NET Developer Community</Company>

<Version>10.5.0-pre</Version>
<AssemblyVersion>10.5.0</AssemblyVersion>
<FileVersion>10.5.0</FileVersion>
<PackageVersion>10.5.0-pre</PackageVersion>
<Version>12.0.1</Version>
<AssemblyVersion>12.0.1</AssemblyVersion>
<FileVersion>12.0.1</FileVersion>
<PackageVersion>12.0.1-pre</PackageVersion>

<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dncuug/X.PagedList.git</RepositoryUrl>
Expand Down
113 changes: 62 additions & 51 deletions src/X.PagedList/BasePagedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,111 @@ namespace X.PagedList;
[PublicAPI]
public abstract class BasePagedList<T> : IPagedList<T>
{
protected List<T> Subset = new();

public const int DefaultPageSize = 100;

protected List<T> Subset = new();

/// <summary>
/// Total number of subsets within the superset.
/// </summary>
public int PageCount { get; protected set; }
/// <value>
/// Total number of subsets within the superset.
/// </value>
public int PageCount => TotalItemCount > 0 ? (int)Math.Ceiling(TotalItemCount / (double)PageSize) : 0;

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

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

/// <summary>
/// Maximum size any individual subset.
/// </summary>
/// <value>
/// Maximum size any individual subset.
/// </value>
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.
/// 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; }
/// <value>
/// 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.
/// </value>
public bool HasPreviousPage => PageCount > 0 && PageNumber <= PageCount && PageNumber > 1;

/// <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; }
/// <value>
/// 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.
/// </value>
public bool HasNextPage => PageCount > 0 && PageNumber <= PageCount && PageNumber < PageCount;

/// <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; }
/// <value>
/// 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.
/// </value>
public bool IsFirstPage => PageCount > 0 && PageNumber <= PageCount && PageNumber == 1;

/// <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; }
/// <value>
/// 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.
/// </value>
public bool IsLastPage => PageCount > 0 && PageNumber <= PageCount && PageNumber == PageCount;

/// <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; }
/// <value>
/// One-based index of the first item in the paged subset, zero if the superset is empty or PageNumber
/// is greater than PageCount.
/// </value>
public int FirstItemOnPage => PageCount > 0 && PageNumber <= PageCount ? (PageNumber - 1) * PageSize + 1 : 0;

/// <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; }
/// <value>
/// One-based index of the last item in the paged subset, zero if the superset is empty or PageNumber
/// is greater than PageCount.
/// </value>
public int LastItemOnPage
{
get
{
int numberOfLastItemOnPage = (PageNumber - 1) * PageSize + 1 + PageSize - 1;

var result = PageCount > 0 && PageNumber <= PageCount
? numberOfLastItemOnPage > TotalItemCount ? TotalItemCount : numberOfLastItemOnPage
: 0;

return result;
}
}

/// <summary>
/// Parameterless constructor.
Expand Down Expand Up @@ -107,54 +153,26 @@ 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
TotalItemCount = totalItemCount;
PageSize = pageSize;
PageNumber = pageNumber;

PageCount = TotalItemCount > 0
? (int)Math.Ceiling(TotalItemCount / (double)PageSize)
: 0;

bool pageNumberIsGood = PageCount > 0 && PageNumber <= PageCount;

HasPreviousPage = pageNumberIsGood && PageNumber > 1;
HasNextPage = pageNumberIsGood && PageNumber < PageCount;
IsFirstPage = pageNumberIsGood && PageNumber == 1;
IsLastPage = pageNumberIsGood && PageNumber == PageCount;

int numberOfFirstItemOnPage = (PageNumber - 1) * PageSize + 1;

FirstItemOnPage = pageNumberIsGood ? numberOfFirstItemOnPage : 0;

int numberOfLastItemOnPage = numberOfFirstItemOnPage + PageSize - 1;

LastItemOnPage = pageNumberIsGood
? numberOfLastItemOnPage > TotalItemCount ? TotalItemCount : numberOfLastItemOnPage
: 0;
}

/// <summary>
/// Returns an enumerator that iterates through the BasePagedList&lt;T&gt;.
/// Returns an enumerator that iterates through the BasePagedList&lt;T&gt;.
/// </summary>
/// <returns>A BasePagedList&lt;T&gt;.Enumerator for the BasePagedList&lt;T&gt;.</returns>
public IEnumerator<T> GetEnumerator()
{
return Subset.GetEnumerator();
}
public IEnumerator<T> GetEnumerator() => Subset.GetEnumerator();

/// <summary>
/// Returns an enumerator that iterates through the BasePagedList&lt;T&gt;.
/// Returns an enumerator that iterates through the BasePagedList&lt;T&gt;.
/// </summary>
/// <returns>A BasePagedList&lt;T&gt;.Enumerator for the BasePagedList&lt;T&gt;.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

///<summary>
/// Gets the element at the specified index.
Expand All @@ -166,11 +184,4 @@ IEnumerator IEnumerable.GetEnumerator()
/// Gets the number of elements contained on this page.
/// </summary>
public virtual int Count => Subset.Count;

///<summary>
/// Gets a non-enumerable copy of this paged list.
///</summary>
///<returns>A non-enumerable copy of this paged list.</returns>
[Obsolete("This method will be removed in future versions")]
public PagedListMetaData GetMetaData() => new(this);
}
13 changes: 2 additions & 11 deletions src/X.PagedList/IPagedList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using JetBrains.Annotations;
using JetBrains.Annotations;
using System.Collections.Generic;

namespace X.PagedList;
Expand All @@ -11,15 +10,7 @@ namespace X.PagedList;
/// <typeparam name="T">The type of object the collection should contain.</typeparam>
/// <seealso cref="IReadOnlyList{T}"/>
[PublicAPI]
public interface IPagedList<out T> : IPagedList, IReadOnlyList<T>
{
///<summary>
/// Gets a non-enumerable copy of this paged list.
///</summary>
///<returns>A non-enumerable copy of this paged list.</returns>
[Obsolete("This method will be removed in future versions")]
PagedListMetaData GetMetaData();
}
public interface IPagedList<out T> : IPagedList, IReadOnlyList<T>;

/// <summary>
/// Represents a subset of a collection of objects that can be individually accessed by index and containing
Expand Down
7 changes: 0 additions & 7 deletions src/X.PagedList/PagedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ public PagedList(IPagedList pagedList, IEnumerable<T> collection)
TotalItemCount = pagedList.TotalItemCount;
PageSize = pagedList.PageSize;
PageNumber = pagedList.PageNumber;
PageCount = pagedList.PageCount;
HasPreviousPage = pagedList.HasPreviousPage;
HasNextPage = pagedList.HasNextPage;
IsFirstPage = pagedList.IsFirstPage;
IsLastPage = pagedList.IsLastPage;
FirstItemOnPage = pagedList.FirstItemOnPage;
LastItemOnPage = pagedList.LastItemOnPage;

Subset.AddRange(collection);

Expand Down
93 changes: 0 additions & 93 deletions src/X.PagedList/PagedListMetaData.cs

This file was deleted.

Loading