Table of Contents

Class PaginationEnumerable<T>

Namespace
Cuemon.Collections.Generic
Assembly
Cuemon.Core.dll

Represents a generic and read-only pagination sequence.

public class PaginationEnumerable<T> : IEnumerable<T>, IEnumerable

Type Parameters

T

The type of elements in the collection.

Inheritance
PaginationEnumerable<T>
Implements
Derived

Examples

The following example demonstrates lazy pagination of a string array using PaginationEnumerable. It shows how to access page 2 with 3 items per page and prints page metadata such as page count and navigation flags.

using System;
using System.Collections.Generic;
using System.Linq;
using Cuemon.Collections.Generic;

namespace MyApp.Examples
{
    public class PaginationEnumerableExample
    {
        public static void Demonstrate()
        {
            var fruits = new[] { "Apple", "Banana", "Cherry", "Date", "Elderberry", "Fig", "Grape", "Honeydew" };

            // Show page 2 with 3 items per page
            var page = new PaginationEnumerable<string>(fruits, () => fruits.Length, setup =>
            {
                setup.PageSize = 3;
                setup.PageNumber = 2;
            });

            Console.WriteLine($"Page {2} of {page.PageCount} (total items: {page.TotalElementCount})");
            Console.WriteLine($"Has previous page: {page.HasPreviousPage}");
            Console.WriteLine($"Has next page: {page.HasNextPage}");
            Console.WriteLine("Items on this page:");
            foreach (var item in page)
            {
                Console.WriteLine($"  {item}");

}}}
}

Constructors

PaginationEnumerable(IEnumerable<T>, Func<int>, Action<PaginationOptions>)

Initializes a new instance of the PaginationEnumerable<T> class.

public PaginationEnumerable(IEnumerable<T> source, Func<int> totalElementCounter, Action<PaginationOptions> setup = null)

Parameters

source IEnumerable<T>

The sequence to turn into a page.

totalElementCounter Func<int>

The total element counter.

setup Action<PaginationOptions>

The PaginationOptions which may be configured.

Properties

FirstPage

Gets a value indicating whether this instance is on the first paged data sequence.

public bool FirstPage { get; }

Property Value

bool

true if this instance is on the first paged data sequence; otherwise, false.

HasNextPage

Gets a value indicating whether this instance has a next paged data sequence.

public bool HasNextPage { get; }

Property Value

bool

true if this instance has a next paged data sequence; otherwise, false.

HasPreviousPage

Gets a value indicating whether this instance has a previous paged data sequence.

public bool HasPreviousPage { get; }

Property Value

bool

true if this instance has a previous paged data sequence; otherwise, false.

LastPage

Gets a value indicating whether this instance is on the last paged data sequence.

public bool LastPage { get; }

Property Value

bool

true if this instance is on the last paged data sequence; otherwise, false.

PageCount

Gets the total amount of pages for the elements in this sequence.

public int PageCount { get; }

Property Value

int

The total amount of pages for the elements in this sequence.

PageSource

Gets the page source of this instance.

protected IEnumerable<T> PageSource { get; }

Property Value

IEnumerable<T>

The page source of this instance.

TotalElementCount

Gets the total number of elements in the sequence before paging is applied.

public int TotalElementCount { get; }

Property Value

int

The total number of elements in the sequence before paging is applied.

Methods

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

An enumerator that can be used to iterate through the collection.

See Also