1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Collections . Immutable ;
3
4
using System . Collections . ObjectModel ;
4
5
using System . Linq ;
5
6
using System . Linq . Expressions ;
@@ -76,15 +77,18 @@ public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, H
76
77
77
78
public class StartsWithGenerator : BaseHqlGeneratorForMethod
78
79
{
80
+ private static readonly MethodInfo MethodWithComparer = ReflectHelper . GetMethodDefinition < string > ( x => x . StartsWith ( null , default ( StringComparison ) ) ) ;
81
+
79
82
public StartsWithGenerator ( )
80
83
{
81
- SupportedMethods = new [ ] { ReflectHelper . GetMethodDefinition < string > ( x => x . StartsWith ( null ) ) } ;
84
+ SupportedMethods = new [ ] { ReflectHelper . GetMethodDefinition < string > ( x => x . StartsWith ( null ) ) , MethodWithComparer } ;
82
85
}
83
86
84
87
public override bool AllowsNullableReturnType ( MethodInfo method ) => false ;
85
88
86
89
public override HqlTreeNode BuildHql ( MethodInfo method , Expression targetObject , ReadOnlyCollection < Expression > arguments , HqlTreeBuilder treeBuilder , IHqlExpressionVisitor visitor )
87
90
{
91
+ LogIgnoredStringComparisonParameter ( method , MethodWithComparer ) ;
88
92
return treeBuilder . Like (
89
93
visitor . Visit ( targetObject ) . AsExpression ( ) ,
90
94
treeBuilder . Concat (
@@ -95,15 +99,18 @@ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
95
99
96
100
public class EndsWithGenerator : BaseHqlGeneratorForMethod
97
101
{
102
+ private static readonly MethodInfo MethodWithComparer = ReflectHelper . GetMethodDefinition < string > ( x => x . EndsWith ( null , default ( StringComparison ) ) ) ;
103
+
98
104
public EndsWithGenerator ( )
99
105
{
100
- SupportedMethods = new [ ] { ReflectHelper . GetMethodDefinition < string > ( x => x . EndsWith ( null ) ) } ;
106
+ SupportedMethods = new [ ] { ReflectHelper . GetMethodDefinition < string > ( x => x . EndsWith ( null ) ) , MethodWithComparer , } ;
101
107
}
102
108
103
109
public override bool AllowsNullableReturnType ( MethodInfo method ) => false ;
104
110
105
111
public override HqlTreeNode BuildHql ( MethodInfo method , Expression targetObject , ReadOnlyCollection < Expression > arguments , HqlTreeBuilder treeBuilder , IHqlExpressionVisitor visitor )
106
112
{
113
+ LogIgnoredStringComparisonParameter ( method , MethodWithComparer ) ;
107
114
return treeBuilder . Like (
108
115
visitor . Visit ( targetObject ) . AsExpression ( ) ,
109
116
treeBuilder . Concat (
@@ -210,18 +217,28 @@ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
210
217
211
218
public class IndexOfGenerator : BaseHqlGeneratorForMethod
212
219
{
220
+ private static readonly MethodInfo MethodWithComparer1 = ReflectHelper . GetMethodDefinition < string > ( x => x . IndexOf ( string . Empty , default ( StringComparison ) ) ) ;
221
+ private static readonly MethodInfo MethodWithComparer2 = ReflectHelper . GetMethodDefinition < string > ( x => x . IndexOf ( string . Empty , 0 , default ( StringComparison ) ) ) ;
222
+
213
223
public IndexOfGenerator ( )
214
224
{
215
225
SupportedMethods = new [ ]
216
226
{
217
227
ReflectHelper . GetMethodDefinition < string > ( s => s . IndexOf ( ' ' ) ) ,
218
228
ReflectHelper . GetMethodDefinition < string > ( s => s . IndexOf ( " " ) ) ,
219
229
ReflectHelper . GetMethodDefinition < string > ( s => s . IndexOf ( ' ' , 0 ) ) ,
220
- ReflectHelper . GetMethodDefinition < string > ( s => s . IndexOf ( " " , 0 ) )
230
+ ReflectHelper . GetMethodDefinition < string > ( s => s . IndexOf ( " " , 0 ) ) ,
231
+ MethodWithComparer1 ,
232
+ MethodWithComparer2 ,
221
233
} ;
222
234
}
223
235
public override HqlTreeNode BuildHql ( MethodInfo method , Expression targetObject , ReadOnlyCollection < Expression > arguments , HqlTreeBuilder treeBuilder , IHqlExpressionVisitor visitor )
224
236
{
237
+ if ( LogIgnoredStringComparisonParameter ( method , MethodWithComparer1 , MethodWithComparer2 ) )
238
+ {
239
+ arguments = arguments . Where ( a => a . Type != typeof ( StringComparison ) ) . ToList ( ) . AsReadOnly ( ) ;
240
+ }
241
+
225
242
HqlMethodCall locate ;
226
243
if ( arguments . Count == 1 )
227
244
{
@@ -244,21 +261,26 @@ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
244
261
245
262
public class ReplaceGenerator : BaseHqlGeneratorForMethod
246
263
{
264
+ private static readonly MethodInfo MethodWithComparer = ReflectHelper . GetMethodDefinition < string > ( x => x . Replace ( string . Empty , string . Empty , default ( StringComparison ) ) ) ;
265
+
247
266
public ReplaceGenerator ( )
248
267
{
249
268
SupportedMethods = new [ ]
250
269
{
251
270
ReflectHelper . GetMethodDefinition < string > ( s => s . Replace ( ' ' , ' ' ) ) ,
252
- ReflectHelper . GetMethodDefinition < string > ( s => s . Replace ( "" , "" ) )
271
+ ReflectHelper . GetMethodDefinition < string > ( s => s . Replace ( "" , "" ) ) ,
272
+ MethodWithComparer ,
253
273
} ;
254
274
}
255
275
256
276
public override HqlTreeNode BuildHql ( MethodInfo method , Expression targetObject , ReadOnlyCollection < Expression > arguments , HqlTreeBuilder treeBuilder , IHqlExpressionVisitor visitor )
257
277
{
258
- return treeBuilder . MethodCall ( "replace" ,
259
- visitor . Visit ( targetObject ) . AsExpression ( ) ,
260
- visitor . Visit ( arguments [ 0 ] ) . AsExpression ( ) ,
261
- visitor . Visit ( arguments [ 1 ] ) . AsExpression ( ) ) ;
278
+ LogIgnoredStringComparisonParameter ( method , MethodWithComparer ) ;
279
+ return treeBuilder . MethodCall (
280
+ "replace" ,
281
+ visitor . Visit ( targetObject ) . AsExpression ( ) ,
282
+ visitor . Visit ( arguments [ 0 ] ) . AsExpression ( ) ,
283
+ visitor . Visit ( arguments [ 1 ] ) . AsExpression ( ) ) ;
262
284
}
263
285
}
264
286
0 commit comments