Class PaginationList<T>
- Namespace
- Cuemon.Collections.Generic
- Assembly
- Cuemon.Core.dll
Represents an eagerly materialized generic and read-only pagination list.
public class PaginationList<T> : PaginationEnumerable<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
TThe type of elements in the collection.
- Inheritance
-
PaginationList<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Examples
The following example demonstrates eager pagination of a customer list using PaginationList. It shows indexer-based access and page metadata such as total items, page count, and first/last page flags.
using System;
using System.Collections.Generic;
using Cuemon.Collections.Generic;
namespace MyApp.Examples
{
public class PaginationListExample
{
public static void Demonstrate()
{
var customers = new List<string>
{
"Alice", "Bob", "Carol", "Dave", "Eve",
"Frank", "Grace", "Hank", "Iris", "Jack",
"Kate", "Leo", "Mia", "Noah", "Olivia"
};
// Eagerly materialize page 3 with 5 items per page
var page = new PaginationList<string>(customers, () => customers.Count, setup =>
{
setup.PageSize = 5;
setup.PageNumber = 3;
});
Console.WriteLine($"Page items (count: {page.Count})");
for (int i = 0; i < page.Count; i++)
{
Console.WriteLine($" [{i}] {page[i]}");
Console.WriteLine($"Total items: {page.TotalElementCount}");
Console.WriteLine($"Total pages: {page.PageCount}");
Console.WriteLine($"First page: {page.FirstPage}");
Console.WriteLine($"Last page: {page.LastPage}");
}}}
}
Constructors
PaginationList(IEnumerable<T>, Func<int>, Action<PaginationOptions>)
Initializes a new instance of the PaginationList<T> class.
public PaginationList(IEnumerable<T> source, Func<int> totalElementCounter, Action<PaginationOptions> setup = null)
Parameters
sourceIEnumerable<T>The sequence to turn into a page.
totalElementCounterFunc<int>The total element counter.
setupAction<PaginationOptions>The PaginationOptions which may be configured.
Properties
Count
Gets the number of elements on the current page.
public int Count { get; }
Property Value
- int
The number of elements on the current page.
this[int]
Gets the element at the specified index.
public T this[int index] { get; }
Parameters
indexintThe zero-based index of the element to get.
Property Value
- T
The element at the specified index.