@@ -13,31 +13,52 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal;
13
13
/// </summary>
14
14
public class CosmosStringMethodTranslator ( ISqlExpressionFactory sqlExpressionFactory ) : IMethodCallTranslator
15
15
{
16
- private static readonly MethodInfo IndexOfMethodInfo
16
+ private static readonly MethodInfo IndexOfMethodInfoString
17
17
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . IndexOf ) , [ typeof ( string ) ] ) ! ;
18
18
19
- private static readonly MethodInfo IndexOfMethodInfoWithStartingPosition
19
+ private static readonly MethodInfo IndexOfMethodInfoChar
20
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . IndexOf ) , [ typeof ( char ) ] ) ! ;
21
+
22
+ private static readonly MethodInfo IndexOfMethodInfoWithStartingPositionString
20
23
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . IndexOf ) , [ typeof ( string ) , typeof ( int ) ] ) ! ;
21
24
22
- private static readonly MethodInfo ReplaceMethodInfo
25
+ private static readonly MethodInfo IndexOfMethodInfoWithStartingPositionChar
26
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . IndexOf ) , [ typeof ( char ) , typeof ( int ) ] ) ! ;
27
+
28
+ private static readonly MethodInfo ReplaceMethodInfoString
23
29
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . Replace ) , [ typeof ( string ) , typeof ( string ) ] ) ! ;
24
30
25
- private static readonly MethodInfo ContainsMethodInfo
31
+ private static readonly MethodInfo ReplaceMethodInfoChar
32
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . Replace ) , [ typeof ( char ) , typeof ( char ) ] ) ! ;
33
+
34
+ private static readonly MethodInfo ContainsMethodInfoString
26
35
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . Contains ) , [ typeof ( string ) ] ) ! ;
27
36
28
- private static readonly MethodInfo ContainsWithStringComparisonMethodInfo
37
+ private static readonly MethodInfo ContainsMethodInfoChar
38
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . Contains ) , [ typeof ( char ) ] ) ! ;
39
+
40
+ private static readonly MethodInfo ContainsWithStringComparisonMethodInfoString
29
41
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . Contains ) , [ typeof ( string ) , typeof ( StringComparison ) ] ) ! ;
30
42
31
- private static readonly MethodInfo StartsWithMethodInfo
43
+ private static readonly MethodInfo ContainsWithStringComparisonMethodInfoChar
44
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . Contains ) , [ typeof ( char ) , typeof ( StringComparison ) ] ) ! ;
45
+
46
+ private static readonly MethodInfo StartsWithMethodInfoString
32
47
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . StartsWith ) , [ typeof ( string ) ] ) ! ;
33
48
34
- private static readonly MethodInfo StartsWithWithStringComparisonMethodInfo
49
+ private static readonly MethodInfo StartsWithMethodInfoChar
50
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . StartsWith ) , [ typeof ( char ) ] ) ! ;
51
+
52
+ private static readonly MethodInfo StartsWithWithStringComparisonMethodInfoString
35
53
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . StartsWith ) , [ typeof ( string ) , typeof ( StringComparison ) ] ) ! ;
36
54
37
- private static readonly MethodInfo EndsWithMethodInfo
55
+ private static readonly MethodInfo EndsWithMethodInfoString
38
56
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . EndsWith ) , [ typeof ( string ) ] ) ! ;
39
57
40
- private static readonly MethodInfo EndsWithWithStringComparisonMethodInfo
58
+ private static readonly MethodInfo EndsWithMethodInfoChar
59
+ = typeof ( string ) . GetRuntimeMethod ( nameof ( string . EndsWith ) , [ typeof ( char ) ] ) ! ;
60
+
61
+ private static readonly MethodInfo EndsWithWithStringComparisonMethodInfoString
41
62
= typeof ( string ) . GetRuntimeMethod ( nameof ( string . EndsWith ) , [ typeof ( string ) , typeof ( StringComparison ) ] ) ! ;
42
63
43
64
private static readonly MethodInfo ToLowerMethodInfo
@@ -109,27 +130,27 @@ private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentSta
109
130
{
110
131
if ( instance != null )
111
132
{
112
- if ( IndexOfMethodInfo . Equals ( method ) )
133
+ if ( IndexOfMethodInfoString . Equals ( method ) || IndexOfMethodInfoChar . Equals ( method ) )
113
134
{
114
135
return TranslateSystemFunction ( "INDEX_OF" , typeof ( int ) , instance , arguments [ 0 ] ) ;
115
136
}
116
137
117
- if ( IndexOfMethodInfoWithStartingPosition . Equals ( method ) )
138
+ if ( IndexOfMethodInfoWithStartingPositionString . Equals ( method ) || IndexOfMethodInfoWithStartingPositionChar . Equals ( method ) )
118
139
{
119
140
return TranslateSystemFunction ( "INDEX_OF" , typeof ( int ) , instance , arguments [ 0 ] , arguments [ 1 ] ) ;
120
141
}
121
142
122
- if ( ReplaceMethodInfo . Equals ( method ) )
143
+ if ( ReplaceMethodInfoString . Equals ( method ) || ReplaceMethodInfoChar . Equals ( method ) )
123
144
{
124
145
return TranslateSystemFunction ( "REPLACE" , method . ReturnType , instance , arguments [ 0 ] , arguments [ 1 ] ) ;
125
146
}
126
147
127
- if ( ContainsMethodInfo . Equals ( method ) )
148
+ if ( ContainsMethodInfoString . Equals ( method ) || ContainsMethodInfoChar . Equals ( method ) )
128
149
{
129
150
return TranslateSystemFunction ( "CONTAINS" , typeof ( bool ) , instance , arguments [ 0 ] ) ;
130
151
}
131
152
132
- if ( ContainsWithStringComparisonMethodInfo . Equals ( method ) )
153
+ if ( ContainsWithStringComparisonMethodInfoString . Equals ( method ) || ContainsWithStringComparisonMethodInfoChar . Equals ( method ) )
133
154
{
134
155
if ( arguments [ 1 ] is SqlConstantExpression { Value : StringComparison comparisonType } )
135
156
{
@@ -150,12 +171,12 @@ private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentSta
150
171
return null ;
151
172
}
152
173
153
- if ( StartsWithMethodInfo . Equals ( method ) )
174
+ if ( StartsWithMethodInfoString . Equals ( method ) || StartsWithMethodInfoChar . Equals ( method ) )
154
175
{
155
176
return TranslateSystemFunction ( "STARTSWITH" , typeof ( bool ) , instance , arguments [ 0 ] ) ;
156
177
}
157
178
158
- if ( StartsWithWithStringComparisonMethodInfo . Equals ( method ) )
179
+ if ( StartsWithWithStringComparisonMethodInfoString . Equals ( method ) )
159
180
{
160
181
if ( arguments [ 1 ] is SqlConstantExpression { Value : StringComparison comparisonType } )
161
182
{
@@ -176,12 +197,12 @@ private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentSta
176
197
return null ;
177
198
}
178
199
179
- if ( EndsWithMethodInfo . Equals ( method ) )
200
+ if ( EndsWithMethodInfoString . Equals ( method ) || EndsWithMethodInfoChar . Equals ( method ) )
180
201
{
181
202
return TranslateSystemFunction ( "ENDSWITH" , typeof ( bool ) , instance , arguments [ 0 ] ) ;
182
203
}
183
204
184
- if ( EndsWithWithStringComparisonMethodInfo . Equals ( method ) )
205
+ if ( EndsWithWithStringComparisonMethodInfoString . Equals ( method ) )
185
206
{
186
207
if ( arguments [ 1 ] is SqlConstantExpression { Value : StringComparison comparisonType } )
187
208
{
0 commit comments