For the following Lambda expression:
GetPropertyNameAndArrayIndex(() => SomeArray[0])
I know that you can get the property name for an expression. I also know that you can get the array index by using a ConstantExpression and accessing the Right value. My question is how do you get array index (or Right value) when it is not a constant, I.E.,
for (int i = 0; i < 5; i++)
{
GetPropertyNameAndArrayIndex(() => SomeArray[i])
}
Any help would be greatly appreciated.
As already noted in comments; note that the example given is susceptible to issues with captured variables if used asynchronously – but probably OK “as is”.
To do it thoroughly involves a lot of edge-cases (or you can cheat and use
Compile()) – but here’s an example that shows the overall themes (without usingCompile):