How to create a .NET expression using the NodeType ExpressionType.Index expression?

I am writing code that evaluates .NET trees Expression. I am trying to create a C # 4 test to implement my processing ExpressionType.Index, but I cannot figure out how to create this type of expression with LambdaExpression. No matter what I try, the expression is expressed as ExpressionType.Callor ExpressionType.ArrayIndex. For instance:

IList<int> myList = new ObservableCollection<int> { 3, 56, 8 };
Expression<Func<int>> myExpression = () => myList[3]; 
// myExpression.Body.NodeType == ExpressionType.Call

myList = new int[] { 3, 56, 8 };
myExpression = () => myList[3]; 
// myExpression.Body.NodeType == ExpressionType.Call

int[] myArray = new int[] { 3, 56, 8 };
myExpression = () => myArray[3]; 
// myExpression.Body.NodeType == ExpressionType.ArrayIndex

List<int> myNonInterfaceList = new List<int> { 3, 7, 4, 2 };
myExpression = () => myNonInterfaceList[3]; 
// myExpression.Body.NodeType == ExpressionType.Call

What is IndexExpressionit and can it be created using the built- LambdaExpressionin in C # 4?

+3
source share
1 answer

An IndexExpression - , (.. ). , DLR. # 4.0 , , IndexExpression . , .

IndexExpression, static ArrayAccess(), MakeIndex() Property() Expression.

+3

Source: https://habr.com/ru/post/1756673/


All Articles