@@ -397,13 +397,25 @@ private protected override BsonDocument RenderArguments(
397
397
{
398
398
if ( ! _useDefaultSerialization )
399
399
{
400
- var min = ToBsonValue ( _range . Min ) ;
401
- var max = ToBsonValue ( _range . Max ) ;
400
+ BsonValue min = null , max = null ;
401
+ bool minInclusive = false , maxInclusive = false ;
402
402
403
- return new BsonDocument
403
+ if ( _range . Min != null )
404
404
{
405
- { _range . IsMinInclusive ? "gte" : "gt" , min , min != BsonNull . Value } ,
406
- { _range . IsMaxInclusive ? "lte" : "lt" , max , max != BsonNull . Value } ,
405
+ min = ToBsonValue ( _range . Min . Value ) ;
406
+ minInclusive = _range . Min . Inclusive ;
407
+ }
408
+
409
+ if ( _range . Max != null )
410
+ {
411
+ max = ToBsonValue ( _range . Max . Value ) ;
412
+ maxInclusive = _range . Max . Inclusive ;
413
+ }
414
+
415
+ return new ( )
416
+ {
417
+ { minInclusive ? "gte" : "gt" , min , min != null } ,
418
+ { maxInclusive ? "lte" : "lt" , max , max != null }
407
419
} ;
408
420
}
409
421
@@ -418,15 +430,15 @@ private protected override BsonDocument RenderArguments(
418
430
using var bsonWriter = new BsonDocumentWriter ( document ) ;
419
431
var context = BsonSerializationContext . CreateRoot ( bsonWriter ) ;
420
432
bsonWriter . WriteStartDocument ( ) ;
421
- if ( _range . Min is not null )
433
+ if ( _range . Min != null )
422
434
{
423
- bsonWriter . WriteName ( _range . IsMinInclusive ? "gte" : "gt" ) ;
424
- valueSerializer . Serialize ( context , _range . Min ) ;
435
+ bsonWriter . WriteName ( _range . Min . Inclusive ? "gte" : "gt" ) ;
436
+ valueSerializer . Serialize ( context , _range . Min . Value ) ;
425
437
}
426
438
if ( _range . Max is not null )
427
439
{
428
- bsonWriter . WriteName ( _range . IsMaxInclusive ? "lte" : "lt" ) ;
429
- valueSerializer . Serialize ( context , _range . Max ) ;
440
+ bsonWriter . WriteName ( _range . Max . Inclusive ? "lte" : "lt" ) ;
441
+ valueSerializer . Serialize ( context , _range . Max . Value ) ;
430
442
}
431
443
bsonWriter . WriteEndDocument ( ) ;
432
444
0 commit comments