@@ -977,56 +977,47 @@ private bool TryTranslateStringMethodCall(MethodCallExpression node, out BsonVal
977
977
}
978
978
break ;
979
979
case "Split" :
980
- BsonValue separator = null ;
981
- var separatorConstant = node . Arguments [ 0 ] as ConstantExpression ;
982
- if ( separatorConstant != null && separatorConstant . Type == typeof ( char [ ] ) )
980
+ if ( node . Arguments . Count < 1 )
983
981
{
984
- var chars = ( char [ ] ) separatorConstant . Value ;
985
- if ( chars . Length == 1 )
986
- {
987
- separator = new BsonString ( new string ( chars ) ) ;
988
- }
982
+ return false ;
989
983
}
990
- else
984
+ if ( node . Arguments [ 0 ] . Type != typeof ( char [ ] ) && node . Arguments [ 0 ] . Type != typeof ( string [ ] ) )
991
985
{
992
- separator = TranslateValue ( node . Arguments [ 0 ] ) ;
993
- var array = separator as BsonArray ;
994
- if ( array != null && array . Count == 1 )
995
- {
996
- separator = array [ 0 ] ;
997
- }
998
- else if ( array != null )
999
- {
1000
- separator = null ;
1001
- }
986
+ return false ;
1002
987
}
1003
-
1004
- if ( separator != null )
988
+ var separatorArray = TranslateValue ( node . Arguments [ 0 ] ) as BsonArray ;
989
+ if ( separatorArray == null || separatorArray . Count != 1 )
990
+ {
991
+ return false ;
992
+ }
993
+ var separator = separatorArray [ 0 ] ;
994
+ if ( separator . BsonType == BsonType . Int32 )
1005
995
{
1006
- if ( node . Arguments . Count == 1 )
996
+ separator = new BsonString ( new string ( ( char ) separator . AsInt32 , 1 ) ) ;
997
+ }
998
+ if ( node . Arguments . Count == 2 )
999
+ {
1000
+ var constantExpression = node . Arguments [ 1 ] as ConstantExpression ;
1001
+ if ( constantExpression == null || constantExpression . Type != typeof ( StringSplitOptions ) )
1007
1002
{
1008
- result = new BsonDocument ( "$split" , new BsonArray
1009
- {
1010
- field ,
1011
- separator
1012
- } ) ;
1013
- return true ;
1003
+ return false ;
1014
1004
}
1015
- else if ( node . Arguments . Count == 2 && node . Arguments [ 1 ] . Type == typeof ( StringSplitOptions ) )
1005
+ var options = ( StringSplitOptions ) constantExpression . Value ;
1006
+ if ( options != StringSplitOptions . None )
1016
1007
{
1017
- var splitOptions = node . Arguments [ 1 ] as ConstantExpression ;
1018
- if ( splitOptions != null && ( ( StringSplitOptions ) splitOptions . Value ) == StringSplitOptions . None )
1019
- {
1020
- result = new BsonDocument ( "$split" , new BsonArray
1021
- {
1022
- field ,
1023
- separator
1024
- } ) ;
1025
- return true ;
1026
- }
1008
+ return false ;
1027
1009
}
1028
1010
}
1029
- break ;
1011
+ if ( node . Arguments . Count > 2 )
1012
+ {
1013
+ return false ;
1014
+ }
1015
+ result = new BsonDocument ( "$split" , new BsonArray
1016
+ {
1017
+ field ,
1018
+ separator
1019
+ } ) ;
1020
+ return true ;
1030
1021
case "Substring" :
1031
1022
if ( node . Arguments . Count == 2 )
1032
1023
{
0 commit comments