Table of Contents

Struct Range<T>

Namespace
NextORM.Core
Assembly
nextorm.core.dll

A provider-agnostic range value: a contiguous interval of T whose bounds may be inclusive or exclusive and may be unbounded on either side, plus the empty range. It mirrors the invariants of the PostgreSQL range types without taking a dependency on a driver; the PostgreSQL provider maps it to int4range/int8range/numrange/tsrange/ tstzrange/daterange.

public readonly struct Range<T> : IEquatable<Range<T>> where T : struct, IComparable<T>

Type Parameters

T

The bound type: int, long, decimal, DateTime, DateTimeOffset or DateOnly.

Implements
Inherited Members
Extension Methods

Remarks

Lower and Upper are the declared bounds and are only meaningful when the matching LowerInfinite/UpperInfinite flag is false; an unbounded side, the empty range and a default(Range<T>) value all have null bounds. The explicit flags (rather than a nullable T alone) keep an unbounded side distinguishable from a real bound that happens to be the default value. PostgreSQL reports both lower_inf and upper_inf as false for the 'empty' literal, which LowerInfinite and UpperInfinite mirror.

Constructors

Range(T?, T?, bool, bool, bool, bool, bool)

Creates a range from the full set of PostgreSQL range characteristics. Used by providers to materialize a value read from the database; prefer the shorter constructors when authoring one.

public Range(T? lower, T? upper, bool lowerInclusive, bool upperInclusive, bool lowerInfinite, bool upperInfinite, bool isEmpty)

Parameters

lower T?

The lower bound, or null when the lower side is unbounded.

upper T?

The upper bound, or null when the upper side is unbounded.

lowerInclusive bool

Whether the lower bound is part of the range.

upperInclusive bool

Whether the upper bound is part of the range.

lowerInfinite bool

Whether the lower side is unbounded.

upperInfinite bool

Whether the upper side is unbounded.

isEmpty bool

Whether this is the empty range; its bounds are then ignored.

Range(T, T)

Creates a range with the PostgreSQL default bounds [lower, upper) (lower inclusive, upper exclusive).

public Range(T lower, T upper)

Parameters

lower T

The lower bound.

upper T

The upper bound.

Range(T, T, bool, bool)

Creates a range from explicit bounds and bound inclusivity.

public Range(T lower, T upper, bool lowerInclusive, bool upperInclusive)

Parameters

lower T

The lower bound.

upper T

The upper bound.

lowerInclusive bool

Whether the lower bound is part of the range.

upperInclusive bool

Whether the upper bound is part of the range.

Range(T, T, bool, bool, bool, bool)

Creates a range from explicit bounds, bound inclusivity and unbounded sides.

public Range(T lower, T upper, bool lowerInclusive, bool upperInclusive, bool lowerInfinite, bool upperInfinite)

Parameters

lower T

The lower bound; ignored when lowerInfinite is true.

upper T

The upper bound; ignored when upperInfinite is true.

lowerInclusive bool

Whether the lower bound is part of the range.

upperInclusive bool

Whether the upper bound is part of the range.

lowerInfinite bool

Whether the lower side is unbounded.

upperInfinite bool

Whether the upper side is unbounded.

Properties

Empty

The empty range: it contains no point and overlaps nothing.

public static Range<T> Empty { get; }

Property Value

Range<T>

IsEmpty

Whether this is the empty range (PostgreSQL isempty, the 'empty' literal).

public bool IsEmpty { get; }

Property Value

bool

Lower

The lower bound, or null when there is no finite lower bound (unbounded or empty).

public T? Lower { get; }

Property Value

T?

LowerInclusive

Whether the lower bound is part of the range. Always false when unbounded or empty.

public bool LowerInclusive { get; }

Property Value

bool

LowerInfinite

Whether the lower side is unbounded (PostgreSQL lower_inf). Always false for the empty range.

public bool LowerInfinite { get; }

Property Value

bool

Upper

The upper bound, or null when there is no finite upper bound (unbounded or empty).

public T? Upper { get; }

Property Value

T?

UpperInclusive

Whether the upper bound is part of the range. Always false when unbounded or empty.

public bool UpperInclusive { get; }

Property Value

bool

UpperInfinite

Whether the upper side is unbounded (PostgreSQL upper_inf). Always false for the empty range.

public bool UpperInfinite { get; }

Property Value

bool

Methods

Equals(Range<T>)

Returns whether this range and other have the same PostgreSQL characteristics.

public bool Equals(Range<T> other)

Parameters

other Range<T>

The range to compare with.

Returns

bool

true when the two ranges are equal.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(Range<T>, Range<T>)

Returns whether two ranges have the same PostgreSQL characteristics.

public static bool operator ==(Range<T> left, Range<T> right)

Parameters

left Range<T>

The left range.

right Range<T>

The right range.

Returns

bool

true when the two ranges are equal.

operator !=(Range<T>, Range<T>)

Returns whether two ranges differ.

public static bool operator !=(Range<T> left, Range<T> right)

Parameters

left Range<T>

The left range.

right Range<T>

The right range.

Returns

bool

true when the two ranges are not equal.