Table of Contents

Struct Pagination

Namespace
Olve.Utilities.Paginations
Assembly
Olve.Utilities.dll

Represents a pagination.

public readonly record struct Pagination : IEquatable<Pagination>
Implements
Inherited Members

Constructors

Pagination(int, int)

Represents a pagination.

public Pagination(int Page, int PageSize)

Parameters

Page int

The (0-based) page number.

PageSize int

The number of items per page.

Properties

Offset

The offset of the pagination.

public int Offset { get; }

Property Value

int

Page

The (0-based) page number.

public int Page { get; init; }

Property Value

int

PageSize

The number of items per page.

public int PageSize { get; init; }

Property Value

int

Methods

Clamp(int, int)

Returns a valid pagination: a negative Page becomes 0, a PageSize of zero or less becomes defaultPageSize, and a PageSize above maxPageSize becomes maxPageSize.

public Pagination Clamp(int defaultPageSize, int maxPageSize)

Parameters

defaultPageSize int

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

maxPageSize int

The largest allowed page size.

Returns

Pagination

The clamped pagination.

Exceptions

ArgumentOutOfRangeException

maxPageSize is less than 1, or defaultPageSize is not between 1 and maxPageSize.

ToOffsetPagination()

Converts this pagination to the equivalent OffsetPagination. This is always possible.

public OffsetPagination ToOffsetPagination()

Returns

OffsetPagination

An OffsetPagination with Offset = Offset and Limit = PageSize.

Validate(int)

Validates that Page is not negative and that PageSize is between 1 and maxPageSize inclusive.

public Result Validate(int maxPageSize)

Parameters

maxPageSize int

The largest allowed page size.

Returns

Result

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