public static RangeBoundaryFrom <T> AdjustAndCreate(T?value, RangeBoundaryFromKind boundaryKind) { DebugCode.AssertArgument( boundaryKind == RangeBoundaryFromKind.Inclusive || boundaryKind == RangeBoundaryFromKind.Exclusive, nameof(boundaryKind), "The boundary kind should be be either Inclusive or Exclusive"); if (_hasNaN && !_equalsFunc(value, value)) { value = default; boundaryKind = RangeBoundaryFromKind.Empty; } if (_hasNegativeInfinity && _equalsFunc(value, _negativeInfinity)) { value = default; boundaryKind = RangeBoundaryFromKind.Infinite; } if (_hasPositiveInfinity && _equalsFunc(value, _positiveInfinity)) { throw CodeExceptions.Argument(nameof(value), "The positive infinity value should not be used for From boundaries."); } if (value == null && boundaryKind != RangeBoundaryFromKind.Empty) { boundaryKind = RangeBoundaryFromKind.Infinite; } #pragma warning disable 618 // Validation not required: value and kind are adjusted return(new RangeBoundaryFrom <T>(value, boundaryKind, SkipsArgValidation)); #pragma warning restore 618 }
/// <summary>Creates a new range boundary.</summary> /// <param name="value"> /// The value of the boundary. /// Infinite (or empty) boundaries should use default(T) or NegativeInfinity(T) (if the type has one) as the value. /// </param> /// <param name="boundaryKind">The kind of the boundary.</param> public RangeBoundaryFrom(T value, RangeBoundaryFromKind boundaryKind) { if (_hasNegativeInfinity && _equalsFunc(value, _negativeInfinity) && boundaryKind != RangeBoundaryFromKind.Empty) { value = default(T); } if (_hasPositiveInfinity && _equalsFunc(value, _positiveInfinity)) { throw CodeExceptions.Argument(nameof(value), "The From boundary does not accept positive infinity value."); } if (boundaryKind != RangeBoundaryFromKind.Inclusive && boundaryKind != RangeBoundaryFromKind.Exclusive) { if (_compareFunc(value, default(T)) != _equalResult) { throw CodeExceptions.Argument(nameof(value), "Value of the infinite/empty boundary should be equal to default(T)."); } } else { if (value == null) { throw CodeExceptions.Argument( nameof(boundaryKind), "BoundaryKind for the null values should be either RangeBoundaryFromKind.Infinite or RangeBoundaryFromKind.Empty."); } } _value = value; _kind = boundaryKind; }
private static Range <T> TryCreateCore <T>( T from, RangeBoundaryFromKind fromKind, T to, RangeBoundaryToKind toKind) => RangeBoundaryFrom <T> .IsValid(from) && RangeBoundaryTo <T> .IsValid(to) ? TryCreate( RangeBoundaryFrom <T> .AdjustAndCreate(from, fromKind), RangeBoundaryTo <T> .AdjustAndCreate(to, toKind)) : Range <T> .Empty;
private static Range <T> TryCreateCore <T>( T from, RangeBoundaryFromKind fromKind, T to, RangeBoundaryToKind toKind) => IsValid(from, to) #pragma warning disable 618 // Validation not required: IsValid() called. ? new Range <T>( RangeBoundaryFrom <T> .AdjustAndCreate(from, fromKind), RangeBoundaryTo <T> .AdjustAndCreate(to, toKind), SkipsArgValidation) #pragma warning restore 618 : Range <T> .Empty;
public static RangeBoundaryFrom <T> AdjustAndCreate(T value, RangeBoundaryFromKind boundaryKind) { if (_hasNegativeInfinity && _equalsFunc(value, _negativeInfinity) && boundaryKind != RangeBoundaryFromKind.Empty) { value = default(T); boundaryKind = RangeBoundaryFromKind.Infinite; } if (_hasPositiveInfinity && _equalsFunc(value, _positiveInfinity)) { throw CodeExceptions.Argument(nameof(value), "The From boundary does not accept positive infinity value."); } if (value == null && boundaryKind != RangeBoundaryFromKind.Empty) { boundaryKind = RangeBoundaryFromKind.Infinite; } #pragma warning disable 618 // Validation not required: value and kind are adjusted return(new RangeBoundaryFrom <T>(value, boundaryKind, SkipsArgValidation)); #pragma warning restore 618 }
internal RangeBoundaryFrom(T value, RangeBoundaryFromKind boundaryKind, UnsafeOverload skipsArgValidation) #if DEBUG : this(value, boundaryKind) { }