@@ -977,44 +977,48 @@ private bool TryTranslateStringMethodCall(MethodCallExpression node, out BsonVal
977
977
}
978
978
break ;
979
979
case "IndexOf" :
980
- var args = new BsonArray { field } ;
981
- if ( node . Arguments [ 0 ] . Type == typeof ( char )
982
- && node . Arguments [ 0 ] . NodeType == ExpressionType . Constant )
980
+ var indexOfArgs = new BsonArray { field } ;
981
+
982
+ if ( node . Arguments . Count < 1 || node . Arguments . Count > 3 )
983
983
{
984
- args . Add ( new BsonString ( ( ( ConstantExpression ) node . Arguments [ 0 ] ) . Value . ToString ( ) ) ) ;
984
+ return false ;
985
985
}
986
- else
986
+
987
+ if ( node . Arguments [ 0 ] . Type != typeof ( char ) && node . Arguments [ 0 ] . Type != typeof ( string ) )
988
+ {
989
+ return false ;
990
+ }
991
+ var value = TranslateValue ( node . Arguments [ 0 ] ) ;
992
+ if ( value . BsonType == BsonType . Int32 )
987
993
{
988
- args . Add ( TranslateValue ( node . Arguments [ 0 ] ) ) ;
994
+ value = new BsonString ( new string ( ( char ) value . AsInt32 , 1 ) ) ;
989
995
}
996
+ indexOfArgs . Add ( value ) ;
990
997
991
998
if ( node . Arguments . Count > 1 )
992
999
{
993
1000
if ( node . Arguments [ 1 ] . Type != typeof ( int ) )
994
1001
{
995
- throw new NotSupportedException ( "The StringComparison parameter is not supported in IndexOf." ) ;
1002
+ return false ;
996
1003
}
997
1004
998
- args . Add ( TranslateValue ( node . Arguments [ 1 ] ) ) ;
1005
+ var startIndex = TranslateValue ( node . Arguments [ 1 ] ) ;
1006
+ indexOfArgs . Add ( startIndex ) ;
999
1007
}
1000
1008
1001
1009
if ( node . Arguments . Count > 2 )
1002
1010
{
1003
1011
if ( node . Arguments [ 2 ] . Type != typeof ( int ) )
1004
1012
{
1005
- throw new NotSupportedException ( "The StringComparison parameter is not supported in IndexOf." ) ;
1013
+ return false ;
1006
1014
}
1007
1015
1008
1016
var count = TranslateValue ( node . Arguments [ 2 ] ) ;
1009
- args . Add ( new BsonDocument ( "$add" , new BsonArray { args [ 2 ] , count } ) ) ;
1010
- }
1011
-
1012
- if ( node . Arguments . Count > 3 )
1013
- {
1014
- throw new NotSupportedException ( "The StringComparison parameter is not supported in IndexOf." ) ;
1017
+ var endIndex = new BsonDocument ( "$add" , new BsonArray { indexOfArgs [ 2 ] , count } ) ;
1018
+ indexOfArgs . Add ( endIndex ) ;
1015
1019
}
1016
1020
1017
- result = new BsonDocument ( "$indexOfBytes" , args ) ;
1021
+ result = new BsonDocument ( "$indexOfBytes" , indexOfArgs ) ;
1018
1022
return true ;
1019
1023
case "Split" :
1020
1024
if ( node . Arguments . Count < 1 || node . Arguments . Count > 2 )
0 commit comments