Struct OffsetPagination
- Namespace
- Olve.Utilities.Paginations
- Assembly
- Olve.Utilities.dll
Represents an offset/limit pagination.
public readonly record struct OffsetPagination : IEquatable<OffsetPagination>
- Implements
- Inherited Members
Constructors
OffsetPagination(int, int)
Represents an offset/limit pagination.
public OffsetPagination(int Offset, int Limit)
Parameters
Properties
Limit
The maximum number of items to take.
public int Limit { get; init; }
Property Value
Offset
The (0-based) number of items to skip.
public int Offset { get; init; }
Property Value
Methods
Clamp(int, int)
Returns a valid pagination: a negative Offset becomes 0, a Limit of zero
or less becomes defaultLimit, and a Limit above
maxLimit becomes maxLimit.
public OffsetPagination Clamp(int defaultLimit, int maxLimit)
Parameters
defaultLimitintThe limit to use when none (zero or less) is given.
maxLimitintThe largest allowed limit.
Returns
- OffsetPagination
The clamped pagination.
Exceptions
- ArgumentOutOfRangeException
maxLimitis less than 1, ordefaultLimitis not between 1 andmaxLimit.
TryToPagination(out Pagination)
Converts this pagination to the equivalent page-based Pagination. This is only possible when Offset is not negative, Limit is positive, and Offset is a multiple of Limit.
public bool TryToPagination(out Pagination pagination)
Parameters
paginationPaginationA Pagination with Page = Offset / Limit and PageSize = Limit, or
defaultwhen no equivalent exists.
Returns
- bool
trueif an equivalent page-based pagination exists; otherwisefalse.
Validate(int)
public Result Validate(int maxLimit)
Parameters
maxLimitintThe largest allowed limit.