TPaginator is a simple, flexible pagination library for .NET, supporting both synchronous and asynchronous pagination strategies. It allows you to easily paginate collections of data with minimal complexity.
- Supports both synchronous and asynchronous pagination strategies.
- Works with IEnumerable (sync) and IQueryable (async).
- Clean and minimalistic API.
- Fully unit-testable with mocks for strategies.
To install TPaginator, run the following command in your NuGet Package Manager console:
dotnet add package TPaginatorTo paginate an IEnumerable<T> collection, use the Paginate method with a synchronous pagination strategy.
// Create a collection
var source = Enumerable.Range(1, 100);
// Initialize the paginator with a synchronous strategy
var paginator = new Paginator<int>(new DefaultPaginationStrategy<int>());
// Paginate the collection
var result = paginator.Paginate(source, page: 2, pageSize: 10);
// Now, you can access these result properties:
int totalPages = result.TotalPages; // Total number of pages
int currentPage = result.CurrentPage; // The current page number
int pageSize = result.PageSize; // The number of items per page
int totalItems = result.TotalItems; // Total number of items in the collection
var itemsOnPage = result.Items; // The list of items for the current page
// Example output:
Console.WriteLine($"Total Pages: {totalPages}");
Console.WriteLine($"Current Page: {currentPage}");
Console.WriteLine($"Page Size: {pageSize}");
Console.WriteLine($"Total Items: {totalItems}");
Console.WriteLine($"Items on Page {currentPage}: {string.Join(", ", itemsOnPage)}");// Create an IQueryable collection
var source = Enumerable.Range(1, 100).AsQueryable();
// Initialize the paginator with an asynchronous strategy
var paginator = new Paginator<int>(new DefaultAsyncPaginationStrategy<int>());
// Paginate the collection asynchronously
var result = await paginator.PaginateAsync(source, page: 2, pageSize: 10);
// Now, you can access these result properties:
int totalPages = result.TotalPages; // Total number of pages
int currentPage = result.CurrentPage; // The current page number
int pageSize = result.PageSize; // The number of items per page
int totalItems = result.TotalItems; // Total number of items in the collection
var itemsOnPage = result.Items; // The list of items for the current page
// Example output:
Console.WriteLine($"Total Pages: {totalPages}");
Console.WriteLine($"Current Page: {currentPage}");
Console.WriteLine($"Page Size: {pageSize}");
Console.WriteLine($"Total Items: {totalItems}");
Console.WriteLine($"Items on Page {currentPage}: {string.Join(", ", itemsOnPage)}");