Table of Contents

Class Page<T>

Namespace
Trellis
Assembly
Trellis.Core.dll

A single page of items from a paginated collection together with the cursors needed to fetch adjacent pages. The canonical Trellis primitive for server-driven pagination.

public sealed record Page<T> : IEquatable<Page<T>>

Type Parameters

T

The item type.

Inheritance
Page<T>
Implements
Inherited Members
Extension Methods

Remarks

Wire shape: Trellis projects Page<T> to 200 OK with a JSON body envelope and a co-emitted Link header (RFC 8288). See Trellis.Asp.HttpResponseExtensions.ToHttpResponse for the Result<Page<T>> overload.

Why not 206 Partial Content? RFC 9110 ยง14 was designed for byte-range transfer of a single octet stream; collection pagination has no IANA-registered range unit and no proxy/CDN ecosystem support. Use Page<T> for collections; for binary downloads, call ASP.NET Core's Results.File(stream, enableRangeProcessing: true) directly.

Cap visibility: RequestedLimit records what the client asked for and AppliedLimit records what the server actually used. WasCapped makes server-side clamping observable without the client having to compare counts.

Constructors

Page(IReadOnlyList<T>, Cursor?, Cursor?, int, int)

Constructs a validated page. Use Empty<T>(int, int) for empty pages.

public Page(IReadOnlyList<T> Items, Cursor? Next, Cursor? Previous, int RequestedLimit, int AppliedLimit)

Parameters

Items IReadOnlyList<T>
Next Cursor
Previous Cursor
RequestedLimit int
AppliedLimit int

Exceptions

ArgumentNullException

Items is null.

ArgumentOutOfRangeException

A limit is non-positive, or AppliedLimit exceeds RequestedLimit.

Properties

AppliedLimit

The limit the server actually applied (after server-side cap).

public int AppliedLimit { get; }

Property Value

int

DeliveredCount

The number of items actually returned in this page.

public int DeliveredCount { get; }

Property Value

int

Items

The immutable items returned for this page.

public IReadOnlyList<T> Items { get; }

Property Value

IReadOnlyList<T>

Next

Cursor for the next page, or null when this is the last page.

public Cursor? Next { get; }

Property Value

Cursor

Previous

Cursor for the previous page, or null when this is the first page (or the source doesn't support reverse).

public Cursor? Previous { get; }

Property Value

Cursor

RequestedLimit

The limit the client requested.

public int RequestedLimit { get; }

Property Value

int

WasCapped

True when the server applied a smaller limit than the client requested.

public bool WasCapped { get; }

Property Value

bool

Methods

Map<TOut>(Func<T, TOut>)

Projects each item to a new type, preserving cursors and limits. Useful when a repository wants to return Page<Dto> instead of Page<Entity> without re-running the cursor/limit ceremony.

public Page<TOut> Map<TOut>(Func<T, TOut> selector)

Parameters

selector Func<T, TOut>

The projection. Required.

Returns

Page<TOut>

A new Page<T> with the same cursors and limits.

Type Parameters

TOut

The projected item type.

Exceptions

ArgumentNullException

selector is null.