@@ -139,7 +139,7 @@ namespace NpgsqlTypes
139139 /// </summary>
140140 /// <param name="lowerBound">The lower bound of the range.</param>
141141 /// <param name="upperBound">The upper bound of the range.</param>
142- public NpgsqlRange ( T lowerBound , T upperBound )
142+ public NpgsqlRange ( [ AllowNull ] T lowerBound , [ AllowNull ] T upperBound )
143143 : this ( lowerBound , true , false , upperBound , true , false ) { }
144144
145145 /// <summary>
@@ -149,7 +149,9 @@ public NpgsqlRange(T lowerBound, T upperBound)
149149 /// <param name="lowerBoundIsInclusive">True if the lower bound is is part of the range (i.e. inclusive); otherwise, false.</param>
150150 /// <param name="upperBound">The upper bound of the range.</param>
151151 /// <param name="upperBoundIsInclusive">True if the upper bound is part of the range (i.e. inclusive); otherwise, false.</param>
152- public NpgsqlRange ( T lowerBound , bool lowerBoundIsInclusive , T upperBound , bool upperBoundIsInclusive )
152+ public NpgsqlRange (
153+ [ AllowNull ] T lowerBound , bool lowerBoundIsInclusive ,
154+ [ AllowNull ] T upperBound , bool upperBoundIsInclusive )
153155 : this ( lowerBound , lowerBoundIsInclusive , false , upperBound , upperBoundIsInclusive , false ) { }
154156
155157 /// <summary>
@@ -161,8 +163,9 @@ public NpgsqlRange(T lowerBound, bool lowerBoundIsInclusive, T upperBound, bool
161163 /// <param name="upperBound">The upper bound of the range.</param>
162164 /// <param name="upperBoundIsInclusive">True if the upper bound is part of the range (i.e. inclusive); otherwise, false.</param>
163165 /// <param name="upperBoundInfinite">True if the upper bound is indefinite (i.e. infinite or unbounded); otherwise, false.</param>
164- public NpgsqlRange ( T lowerBound , bool lowerBoundIsInclusive , bool lowerBoundInfinite ,
165- T upperBound , bool upperBoundIsInclusive , bool upperBoundInfinite )
166+ public NpgsqlRange (
167+ [ AllowNull ] T lowerBound , bool lowerBoundIsInclusive , bool lowerBoundInfinite ,
168+ [ AllowNull ] T upperBound , bool upperBoundIsInclusive , bool upperBoundInfinite )
166169 : this (
167170 lowerBound ,
168171 upperBound ,
@@ -204,7 +207,7 @@ internal NpgsqlRange([AllowNull] T lowerBound, [AllowNull] T upperBound, RangeFl
204207 /// <returns>
205208 /// True if the range is implicitly empty; otherwise, false.
206209 /// </returns>
207- static bool IsEmptyRange ( T lowerBound , T upperBound , RangeFlags flags )
210+ static bool IsEmptyRange ( [ AllowNull ] T lowerBound , [ AllowNull ] T upperBound , RangeFlags flags )
208211 {
209212 // ---------------------------------------------------------------------------------
210213 // We only want to check for those conditions that are unambiguously erroneous:
@@ -227,15 +230,16 @@ static bool IsEmptyRange(T lowerBound, T upperBound, RangeFlags flags)
227230 if ( ( flags & RangeFlags . Inclusive ) == RangeFlags . Inclusive )
228231 return false ;
229232
233+ if ( lowerBound is null || upperBound is null )
234+ return false ;
235+
230236 if ( ! HasEquatableBounds )
231237 return lowerBound ? . Equals ( upperBound ) ?? false ;
232238
233- var lower = ( IEquatable < T > ? ) lowerBound ;
234- var upper = ( IEquatable < T > ? ) upperBound ;
239+ var lower = ( IEquatable < T > ) lowerBound ;
240+ var upper = ( IEquatable < T > ) upperBound ;
235241
236- return lower != null && ! lower . Equals ( default ! ) &&
237- upper != null && ! upper . Equals ( default ! ) &&
238- lower . Equals ( upperBound ) ;
242+ return ! lower . Equals ( default ! ) && ! upper . Equals ( default ! ) && lower . Equals ( upperBound ) ;
239243 }
240244
241245 /// <summary>
@@ -303,13 +307,22 @@ public bool Equals(NpgsqlRange<T> other)
303307 return false ;
304308
305309 if ( HasEquatableBounds )
306- return
307- ( LowerBound == null ? other . LowerBound == null : ( ( IEquatable < T > ) LowerBound ) . Equals ( other . LowerBound ) ) &&
308- ( UpperBound == null ? other . UpperBound == null : ( ( IEquatable < T > ) UpperBound ) . Equals ( other . UpperBound ) ) ;
310+ {
311+ var lowerEqual = LowerBound is null
312+ ? other . LowerBound is null
313+ : ! ( other . LowerBound is null ) && ( ( IEquatable < T > ) LowerBound ) . Equals ( other . LowerBound ) ;
314+
315+ if ( ! lowerEqual )
316+ return false ;
317+
318+ return UpperBound is null
319+ ? other . UpperBound is null
320+ : ! ( other . UpperBound is null ) && ( ( IEquatable < T > ) UpperBound ) . Equals ( other . UpperBound ) ;
321+ }
309322
310323 return
311- ( LowerBound ? . Equals ( other . LowerBound ) ?? other . LowerBound == null ) &&
312- ( UpperBound ? . Equals ( other . UpperBound ) ?? other . UpperBound == null ) ;
324+ ( LowerBound ? . Equals ( other . LowerBound ) ?? other . LowerBound is null ) &&
325+ ( UpperBound ? . Equals ( other . UpperBound ) ?? other . UpperBound is null ) ;
313326 }
314327
315328 /// <inheritdoc />
0 commit comments