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
TThe item type.
- Inheritance
-
Page<T>
- Implements
-
IEquatable<Page<T>>
- 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
ItemsIReadOnlyList<T>NextCursorPreviousCursorRequestedLimitintAppliedLimitint
Exceptions
- ArgumentNullException
Itemsisnull.- ArgumentOutOfRangeException
A limit is non-positive, or
AppliedLimitexceedsRequestedLimit.
Properties
AppliedLimit
The limit the server actually applied (after server-side cap).
public int AppliedLimit { get; }
Property Value
DeliveredCount
The number of items actually returned in this page.
public int DeliveredCount { get; }
Property Value
Items
The immutable items returned for this page.
public IReadOnlyList<T> Items { get; }
Property Value
Next
Cursor for the next page, or null when this is the last page.
public Cursor? Next { get; }
Property Value
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
RequestedLimit
The limit the client requested.
public int RequestedLimit { get; }
Property Value
WasCapped
True when the server applied a smaller limit than the client requested.
public bool WasCapped { get; }
Property Value
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
selectorFunc<T, TOut>The projection. Required.
Returns
Type Parameters
TOutThe projected item type.
Exceptions
- ArgumentNullException
selectorisnull.