Struct Range<T>
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
- Implements
-
IEquatable<Range<T>>
- 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
lowerT?The lower bound, or null when the lower side is unbounded.
upperT?The upper bound, or null when the upper side is unbounded.
lowerInclusiveboolWhether the lower bound is part of the range.
upperInclusiveboolWhether the upper bound is part of the range.
lowerInfiniteboolWhether the lower side is unbounded.
upperInfiniteboolWhether the upper side is unbounded.
isEmptyboolWhether 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
lowerTThe lower bound.
upperTThe 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
lowerTThe lower bound.
upperTThe upper bound.
lowerInclusiveboolWhether the lower bound is part of the range.
upperInclusiveboolWhether 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
lowerTThe lower bound; ignored when
lowerInfiniteis true.upperTThe upper bound; ignored when
upperInfiniteis true.lowerInclusiveboolWhether the lower bound is part of the range.
upperInclusiveboolWhether the upper bound is part of the range.
lowerInfiniteboolWhether the lower side is unbounded.
upperInfiniteboolWhether 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
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
LowerInfinite
Whether the lower side is unbounded (PostgreSQL lower_inf). Always false for the empty range.
public bool LowerInfinite { get; }
Property Value
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
UpperInfinite
Whether the upper side is unbounded (PostgreSQL upper_inf). Always false for the empty range.
public bool UpperInfinite { get; }
Property Value
Methods
Equals(Range<T>)
Returns whether this range and other have the same PostgreSQL characteristics.
public bool Equals(Range<T> other)
Parameters
otherRange<T>The range to compare with.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
Returns
operator !=(Range<T>, Range<T>)
Returns whether two ranges differ.
public static bool operator !=(Range<T> left, Range<T> right)