I extend Dynamic.cs to qualify it for usage with indexers. In this scenario I need to get the index, which is stored in a call expression. In the debugger, I can see:
- left {Param_0.get_Item(0)} System.Linq.Expressions.Expression {System.Linq.Expressions.InstanceMethodCallExpressionN}
- Arguments Count = 1 System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.Expression> {System.Runtime.CompilerServices.TrueReadOnlyCollection<System.Linq.Expressions.Expression>}
- [0] {0} System.Linq.Expressions.Expression {System.Linq.Expressions.ConstantExpression}
CanReduce false bool
DebugView "0" string
NodeType Constant System.Linq.Expressions.ExpressionType
+ Type {Name = "Int32" FullName = "System.Int32"} System.Type {System.RuntimeType}
Value 0 object {int}
+ Rohdatenansicht
What I want is:
left.Arguments[0].Value
How can I get this?
An ugly method will be perhaps to use left.ToString(). This will result in: “Param_0.get_Item(0)” There I can extract the parameter of get_Item(). But I think this is not the right way.
To get to that value, you just need to cast the expressions to the right types:
Alternatively, you can use
dynamic: