Class Slice<T>
- Namespace
- Olve.Utilities.Paginations
- Assembly
- Olve.Utilities.dll
A contiguous slice of items from a larger collection, addressed by offset and limit, with metadata describing position within that collection.
public sealed record Slice<T> : IEquatable<Slice<T>>
Type Parameters
T
- Inheritance
-
Slice<T>
- Implements
-
IEquatable<Slice<T>>
- Inherited Members
Constructors
Slice(IReadOnlyList<T>, int, int, int)
A contiguous slice of items from a larger collection, addressed by offset and limit, with metadata describing position within that collection.
public Slice(IReadOnlyList<T> Items, int Offset, int Limit, int TotalCount)
Parameters
ItemsIReadOnlyList<T>The items in this slice.
OffsetintZero-based index of the first item of this slice within the collection.
LimitintMaximum number of items per slice.
TotalCountintTotal number of items in the collection.
Properties
HasMore
Whether more items exist after this slice.
public bool HasMore { get; }
Property Value
Items
The items in this slice.
public IReadOnlyList<T> Items { get; init; }
Property Value
Limit
Maximum number of items per slice.
public int Limit { get; init; }
Property Value
Next
The OffsetPagination that would fetch the next slice, or
null when this is the last slice.
public OffsetPagination? Next { get; }
Property Value
Offset
Zero-based index of the first item of this slice within the collection.
public int Offset { get; init; }
Property Value
TotalCount
Total number of items in the collection.
public int TotalCount { get; init; }
Property Value
Methods
TryToPage(out Page<T>?)
Converts this slice to the equivalent Page<T>. This is only possible when Offset is a multiple of Limit (see TryToPagination(out Pagination)).
public bool TryToPage(out Page<T>? page)
Parameters
pagePage<T>The equivalent page, or
nullwhen no equivalent exists.
Returns
- bool
trueif an equivalent page exists; otherwisefalse.