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?
source
share