Table of Contents

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

Offset int

The (0-based) number of items to skip.

Limit int

The maximum number of items to take.

Properties

Limit

The maximum number of items to take.

public int Limit { get; init; }

Property Value

int

Offset

The (0-based) number of items to skip.

public int Offset { get; init; }

Property Value

int

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

defaultLimit int

The limit to use when none (zero or less) is given.

maxLimit int

The largest allowed limit.

Returns

OffsetPagination

The clamped pagination.

Exceptions

ArgumentOutOfRangeException

maxLimit is less than 1, or defaultLimit is not between 1 and maxLimit.

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

pagination Pagination

A Pagination with Page = Offset / Limit and PageSize = Limit, or default when no equivalent exists.

Returns

bool

true if an equivalent page-based pagination exists; otherwise false.

Validate(int)

Validates that Offset is not negative and that Limit is between 1 and maxLimit inclusive.

public Result Validate(int maxLimit)

Parameters

maxLimit int

The largest allowed limit.

Returns

Result

A successful Result, or a failure listing every violated rule.