@@ -267,8 +267,7 @@ public static AstExpression Convert(
267
267
Ensure . IsNotNull ( input , nameof ( input ) ) ;
268
268
Ensure . IsNotNull ( to , nameof ( to ) ) ;
269
269
270
- if ( to is AstConstantExpression toConstantExpression &&
271
- ( toConstantExpression . Value as BsonString ) ? . Value is { } toValue &&
270
+ if ( to . IsStringConstant ( out var toValue ) &&
272
271
subType == null &&
273
272
byteOrder == null &&
274
273
format == null &&
@@ -375,26 +374,26 @@ public static AstExpression DerivativeOrIntegralWindowExpression(AstDerivativeOr
375
374
376
375
public static AstExpression Divide ( AstExpression arg1 , AstExpression arg2 )
377
376
{
378
- if ( arg1 is AstConstantExpression constant1 && arg2 is AstConstantExpression constant2 )
377
+ if ( arg1 . IsConstant ( out var constant1 ) && arg2 . IsConstant ( out var constant2 ) )
379
378
{
380
379
return Divide ( constant1 , constant2 ) ;
381
380
}
382
381
383
382
return new AstBinaryExpression ( AstBinaryOperator . Divide , arg1 , arg2 ) ;
384
383
385
- static AstExpression Divide ( AstConstantExpression constant1 , AstConstantExpression constant2 )
384
+ static AstExpression Divide ( BsonValue constant1 , BsonValue constant2 )
386
385
{
387
- return ( constant1 . Value . BsonType , constant2 . Value . BsonType ) switch
386
+ return ( constant1 . BsonType , constant2 . BsonType ) switch
388
387
{
389
- ( BsonType . Double , BsonType . Double ) => constant1 . Value . AsDouble / constant2 . Value . AsDouble ,
390
- ( BsonType . Double , BsonType . Int32 ) => constant1 . Value . AsDouble / constant2 . Value . AsInt32 ,
391
- ( BsonType . Double , BsonType . Int64 ) => constant1 . Value . AsDouble / constant2 . Value . AsInt64 ,
392
- ( BsonType . Int32 , BsonType . Double ) => constant1 . Value . AsInt32 / constant2 . Value . AsDouble ,
393
- ( BsonType . Int32 , BsonType . Int32 ) => ( double ) constant1 . Value . AsInt32 / constant2 . Value . AsInt32 ,
394
- ( BsonType . Int32 , BsonType . Int64 ) => ( double ) constant1 . Value . AsInt32 / constant2 . Value . AsInt64 ,
395
- ( BsonType . Int64 , BsonType . Double ) => constant1 . Value . AsInt64 / constant2 . Value . AsDouble ,
396
- ( BsonType . Int64 , BsonType . Int32 ) => ( double ) constant1 . Value . AsInt64 / constant2 . Value . AsInt32 ,
397
- ( BsonType . Int64 , BsonType . Int64 ) => ( double ) constant1 . Value . AsInt64 / constant2 . Value . AsInt64 ,
388
+ ( BsonType . Double , BsonType . Double ) => constant1 . AsDouble / constant2 . AsDouble ,
389
+ ( BsonType . Double , BsonType . Int32 ) => constant1 . AsDouble / constant2 . AsInt32 ,
390
+ ( BsonType . Double , BsonType . Int64 ) => constant1 . AsDouble / constant2 . AsInt64 ,
391
+ ( BsonType . Int32 , BsonType . Double ) => constant1 . AsInt32 / constant2 . AsDouble ,
392
+ ( BsonType . Int32 , BsonType . Int32 ) => ( double ) constant1 . AsInt32 / constant2 . AsInt32 ,
393
+ ( BsonType . Int32 , BsonType . Int64 ) => ( double ) constant1 . AsInt32 / constant2 . AsInt64 ,
394
+ ( BsonType . Int64 , BsonType . Double ) => constant1 . AsInt64 / constant2 . AsDouble ,
395
+ ( BsonType . Int64 , BsonType . Int32 ) => ( double ) constant1 . AsInt64 / constant2 . AsInt32 ,
396
+ ( BsonType . Int64 , BsonType . Int64 ) => ( double ) constant1 . AsInt64 / constant2 . AsInt64 ,
398
397
_ => new AstBinaryExpression ( AstBinaryOperator . Divide , constant1 , constant2 )
399
398
} ;
400
399
}
@@ -829,9 +828,9 @@ public static AstExpression StrLenBytes(AstExpression arg)
829
828
830
829
public static AstExpression StrLenCP ( AstExpression arg )
831
830
{
832
- if ( arg is AstConstantExpression constantExpression && constantExpression . Value . BsonType == BsonType . String )
831
+ if ( arg . IsStringConstant ( out var stringConstant ) )
833
832
{
834
- var value = constantExpression . Value . AsString . Length ;
833
+ var value = stringConstant . Length ;
835
834
return new AstConstantExpression ( value ) ;
836
835
}
837
836
return new AstUnaryExpression ( AstUnaryOperator . StrLenCP , arg ) ;
@@ -890,9 +889,9 @@ public static AstExpression Switch(IEnumerable<(AstExpression Case, AstExpressio
890
889
891
890
public static AstExpression ToLower ( AstExpression arg )
892
891
{
893
- if ( arg is AstConstantExpression constantExpression && constantExpression . Value . BsonType == BsonType . String )
892
+ if ( arg . IsStringConstant ( out var stringConstant ) )
894
893
{
895
- var value = constantExpression . Value . AsString . ToLowerInvariant ( ) ;
894
+ var value = stringConstant . ToLowerInvariant ( ) ;
896
895
return new AstConstantExpression ( value ) ;
897
896
}
898
897
@@ -906,9 +905,9 @@ public static AstExpression ToString(AstExpression arg)
906
905
907
906
public static AstExpression ToUpper ( AstExpression arg )
908
907
{
909
- if ( arg is AstConstantExpression constantExpression && constantExpression . Value . BsonType == BsonType . String )
908
+ if ( arg . IsStringConstant ( out var stringConstant ) )
910
909
{
911
- var value = constantExpression . Value . AsString . ToUpperInvariant ( ) ;
910
+ var value = stringConstant . ToUpperInvariant ( ) ;
912
911
return new AstConstantExpression ( value ) ;
913
912
}
914
913
@@ -985,7 +984,7 @@ public static AstExpression Zip(IEnumerable<AstExpression> inputs, bool? useLong
985
984
// private static methods
986
985
private static bool AllArgsAreConstantBools ( AstExpression [ ] args , out List < bool > values )
987
986
{
988
- if ( args . All ( arg => arg is AstConstantExpression constantExpression && constantExpression . Value . BsonType == BsonType . Boolean ) )
987
+ if ( args . All ( arg => arg . IsBooleanConstant ( ) ) )
989
988
{
990
989
values = args . Select ( arg => ( ( AstConstantExpression ) arg ) . Value . AsBoolean ) . ToList ( ) ;
991
990
return true ;
@@ -997,7 +996,7 @@ private static bool AllArgsAreConstantBools(AstExpression[] args, out List<bool>
997
996
998
997
private static bool AllArgsAreConstantInt32s ( AstExpression [ ] args , out List < int > values )
999
998
{
1000
- if ( args . All ( arg => arg is AstConstantExpression constantExpression && constantExpression . Value . BsonType == BsonType . Int32 ) )
999
+ if ( args . All ( arg => arg . IsInt32Constant ( ) ) )
1001
1000
{
1002
1001
values = args . Select ( arg => ( ( AstConstantExpression ) arg ) . Value . AsInt32 ) . ToList ( ) ;
1003
1002
return true ;
0 commit comments