File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
tests/LinqKit.Tests.Net452 Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,9 @@ public virtual Expression Visit(Expression exp)
84
84
case ExpressionType . ListInit :
85
85
return VisitListInit ( ( ListInitExpression ) exp ) ;
86
86
#if ! NET35
87
+ case ExpressionType . Index:
88
+ return VisitIndex ( ( IndexExpression ) exp ) ;
89
+
87
90
case ExpressionType . Extension:
88
91
return VisitExtension ( exp ) ;
89
92
#endif
@@ -400,6 +403,20 @@ protected virtual Expression VisitInvocation(InvocationExpression iv)
400
403
Expression expr = Visit ( iv . Expression ) ;
401
404
return args != iv . Arguments || expr != iv . Expression ? Expression . Invoke ( expr , args ) : iv ;
402
405
}
406
+
407
+ #if ! NET35
408
+ /// <summary> Visit index expression </summary>
409
+ protected virtual Expression VisitIndex ( IndexExpression exp )
410
+ {
411
+ var obj = Visit ( exp . Object ) ;
412
+ var args = VisitExpressionList ( exp . Arguments ) ;
413
+ if ( obj != exp . Object || args != exp . Arguments )
414
+ {
415
+ return Expression . MakeIndex ( obj , exp . Indexer , args ) ;
416
+ }
417
+ return exp ;
418
+ }
419
+ #endif
403
420
}
404
421
}
405
422
#endif
Original file line number Diff line number Diff line change 1
- using System . Linq . Expressions ;
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Linq . Expressions ;
2
5
using Xunit ;
3
6
4
7
namespace LinqKit . Tests . Net452
@@ -28,5 +31,20 @@ public void ExpressionCombiner_Expression_UnaryPlus()
28
31
var executed = exp . Expand ( ) . ToString ( ) ;
29
32
Assert . Equal ( exp . ToString ( ) , executed ) ;
30
33
}
34
+
35
+ [ Fact ]
36
+ public void ExpressionExpander_Expression_Index ( )
37
+ {
38
+ var listParameter = Expression . Parameter ( typeof ( List < string > ) , "l" ) ;
39
+ Expression < Func < List < string > , string > > expression1 = Expression . Lambda < Func < List < string > , string > > ( Expression . MakeIndex (
40
+ listParameter ,
41
+ typeof ( List < string > ) . GetProperties ( ) . SingleOrDefault ( p => p . GetIndexParameters ( ) . Length > 0 ) ,
42
+ new [ ] { Expression . Constant ( 0 ) } ) ,
43
+ listParameter ) ;
44
+ Expression < Func < string , string > > expression2 = s => s ;
45
+
46
+ var executed = Linq . Expr ( ( List < string > l ) => expression2 . Invoke ( expression1 . Invoke ( l ) ) ) . Expand ( ) . ToString ( ) ;
47
+ Assert . Equal ( expression1 . ToString ( ) , executed ) ;
48
+ }
31
49
}
32
50
}
You can’t perform that action at this time.
0 commit comments