Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TPaginator

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.

Features

  • 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.

Installation

To install TPaginator, run the following command in your NuGet Package Manager console:

dotnet add package TPaginator

Usage

Synchronous Pagination

To 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)}");

Asynchronous Pagination

// 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)}");

About

TPaginator is a simple and flexible pagination library for .NET

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages