How does one create a .NET Expression with NodeType of ExpressionType.Index?
I'm writing code that evaluates .NET Expression trees. I'm trying to create a C# 4 test to exercise my handling of an ExpressionType.Index , but I can't figure out how to create that type of expression through a LambdaExpression . No matter what I try, the expression comes out as an ExpressionType.Call or ExpressionType.ArrayIndex . For example: 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