6
6
using System . Linq . Dynamic . Core . Tests . TestHelpers ;
7
7
using System . Linq . Expressions ;
8
8
using System . Reflection ;
9
- using System . Runtime . CompilerServices ;
10
9
using FluentAssertions ;
11
10
using Moq ;
12
11
using NFluent ;
@@ -77,11 +76,6 @@ public class ComplexParseLambda3Result
77
76
public int TotalIncome { get ; set ; }
78
77
}
79
78
80
- public class CustomClassWithStaticMethod
81
- {
82
- public static int GetAge ( int x ) => x ;
83
- }
84
-
85
79
public class CustomClassWithMethod
86
80
{
87
81
public int GetAge ( int x ) => x ;
@@ -121,7 +115,7 @@ public CustomTextClass(string origin)
121
115
122
116
public static implicit operator string ( CustomTextClass customTextValue )
123
117
{
124
- return customTextValue ? . Origin ;
118
+ return customTextValue . Origin ;
125
119
}
126
120
127
121
public static implicit operator CustomTextClass ( string origin )
@@ -256,67 +250,6 @@ public override string ToString()
256
250
}
257
251
}
258
252
259
- public static class StaticHelper
260
- {
261
- public static Guid ? GetGuid ( string name )
262
- {
263
- return Guid . NewGuid ( ) ;
264
- }
265
-
266
- public static string Filter ( string filter )
267
- {
268
- return filter ;
269
- }
270
- }
271
-
272
- public class TestCustomTypeProvider : AbstractDynamicLinqCustomTypeProvider , IDynamicLinkCustomTypeProvider
273
- {
274
- private HashSet < Type > _customTypes ;
275
-
276
- public virtual HashSet < Type > GetCustomTypes ( )
277
- {
278
- if ( _customTypes != null )
279
- {
280
- return _customTypes ;
281
- }
282
-
283
- _customTypes = new HashSet < Type > ( FindTypesMarkedWithDynamicLinqTypeAttribute ( new [ ] { GetType ( ) . GetTypeInfo ( ) . Assembly } ) )
284
- {
285
- typeof ( CustomClassWithStaticMethod ) ,
286
- typeof ( StaticHelper )
287
- } ;
288
- return _customTypes ;
289
- }
290
-
291
- public Dictionary < Type , List < MethodInfo > > GetExtensionMethods ( )
292
- {
293
- var types = GetCustomTypes ( ) ;
294
-
295
- var list = new List < Tuple < Type , MethodInfo > > ( ) ;
296
-
297
- foreach ( var type in types )
298
- {
299
- var extensionMethods = type . GetMethods ( BindingFlags . Static | BindingFlags . Public | BindingFlags . NonPublic )
300
- . Where ( x => x . IsDefined ( typeof ( ExtensionAttribute ) , false ) ) . ToList ( ) ;
301
-
302
- extensionMethods . ForEach ( x => list . Add ( new Tuple < Type , MethodInfo > ( x . GetParameters ( ) [ 0 ] . ParameterType , x ) ) ) ;
303
- }
304
-
305
- return list . GroupBy ( x => x . Item1 , tuple => tuple . Item2 ) . ToDictionary ( key => key . Key , methods => methods . ToList ( ) ) ;
306
- }
307
-
308
- public Type ResolveType ( string typeName )
309
- {
310
- return Type . GetType ( typeName ) ;
311
- }
312
-
313
- public Type ResolveTypeBySimpleName ( string typeName )
314
- {
315
- var assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) ;
316
- return ResolveTypeBySimpleName ( assemblies , typeName ) ;
317
- }
318
- }
319
-
320
253
[ Fact ]
321
254
public void DynamicExpressionParser_ParseLambda_UseParameterizedNamesInDynamicQuery_false_String ( )
322
255
{
@@ -1405,15 +1338,15 @@ public void DynamicExpressionParser_ParseLambda_CustomType_Method_With_Expressio
1405
1338
var user = new User ( ) ;
1406
1339
1407
1340
// Act : char
1408
- var expressionTextChar = "StaticHelper.Filter(\" C == 'x '\" )" ;
1341
+ var expressionTextChar = "StaticHelper.Filter(\" C == 'c '\" )" ;
1409
1342
var lambdaChar = DynamicExpressionParser . ParseLambda ( config , typeof ( User ) , null , expressionTextChar , user ) ;
1410
1343
var funcChar = ( Expression < Func < User , string > > ) lambdaChar ;
1411
1344
1412
1345
var delegateChar = funcChar . Compile ( ) ;
1413
1346
var resultChar = ( string ? ) delegateChar . DynamicInvoke ( user ) ;
1414
1347
1415
1348
// Assert : int
1416
- resultChar . Should ( ) . Be ( "C == 'x '" ) ;
1349
+ resultChar . Should ( ) . Be ( "C == 'c '" ) ;
1417
1350
1418
1351
// Act : int
1419
1352
var expressionTextIncome = "StaticHelper.Filter(\" Income == 5\" )" ;
@@ -1435,7 +1368,53 @@ public void DynamicExpressionParser_ParseLambda_CustomType_Method_With_Expressio
1435
1368
var resultUserName = ( string ? ) delegateUserName . DynamicInvoke ( user ) ;
1436
1369
1437
1370
// Assert : string
1438
- resultUserName . Should ( ) . Be ( @"UserName == ""x""""""" ) ;
1371
+ resultUserName . Should ( ) . Be ( @"UserName == ""x""" ) ;
1372
+ }
1373
+
1374
+ [ Fact ]
1375
+ public void DynamicExpressionParser_ParseLambda_CustomType_Method_With_ComplexExpression1String ( )
1376
+ {
1377
+ // Arrange
1378
+ var config = new ParsingConfig
1379
+ {
1380
+ CustomTypeProvider = new TestCustomTypeProvider ( )
1381
+ } ;
1382
+
1383
+ var user = new User ( ) ;
1384
+
1385
+ // Act
1386
+ var expressionText = @"StaticHelper.In(Id, StaticHelper.SubSelect(""Identity"", ""LegalPerson"", ""StaticHelper.In(ParentId, StaticHelper.SubSelect(""""LegalPersonId"""", """"PointSiteTD"""", """"Identity = 5"""", """"""""))"", """"))" ;
1387
+ var lambda = DynamicExpressionParser . ParseLambda ( config , typeof ( User ) , null , expressionText , user ) ;
1388
+ var func = ( Expression < Func < User , bool > > ) lambda ;
1389
+
1390
+ var compile = func . Compile ( ) ;
1391
+ var result = ( bool ? ) compile . DynamicInvoke ( user ) ;
1392
+
1393
+ // Assert
1394
+ result . Should ( ) . Be ( false ) ;
1395
+ }
1396
+
1397
+ [ Fact ]
1398
+ public void DynamicExpressionParser_ParseLambda_CustomType_Method_With_ComplexExpression2String ( )
1399
+ {
1400
+ // Arrange
1401
+ var config = new ParsingConfig
1402
+ {
1403
+ CustomTypeProvider = new TestCustomTypeProvider ( )
1404
+ } ;
1405
+
1406
+ var user = new User ( ) ;
1407
+
1408
+ // Act
1409
+ var expressionText = @"StaticHelper.In(Id, StaticHelper.SubSelect(""Identity"", ""LegalPerson"", ""StaticHelper.In(ParentId, StaticHelper.SubSelect(""""LegalPersonId"""", """"PointSiteTD"""", """"Identity = "" + StaticHelper.ToExpressionString(StaticHelper.Get(""CurrentPlace""), 2) + """""", """"""""))"", """"))" ;
1410
+ var lambda = DynamicExpressionParser . ParseLambda ( config , typeof ( User ) , null , expressionText , user ) ;
1411
+ var func = ( Expression < Func < User , bool > > ) lambda ;
1412
+
1413
+ var compile = func . Compile ( ) ;
1414
+ var result = ( bool ? ) compile . DynamicInvoke ( user ) ;
1415
+
1416
+ // Assert
1417
+ result . Should ( ) . Be ( false ) ;
1439
1418
}
1440
1419
1441
1420
[ Theory ]
0 commit comments