Hello,
I wonder if you can create and modify a Expression Tree out of a existing delegate.
Kinda like
public void Foo() {
Console.WriteLine(1000);
}
....
Expression exp = Foo.GetExpression();
//Now do something what changes 1000 to 2000...
So I would like to reverse engineer a allready excisting Method.
My problem is that I have a construction like this:
var acts = new Action[20];
for (int i = 0; i != 20; i++)
acts[i] = () => { Console.WriteLine(i); };
and by the way C# works all acts do the same (prints 20). But I want that that
acts[5]()
print 5
acts[11]()
prints 11 and so on.
So I need to compute 20 different delegates and I wonder what's a "nice" approach to do so. Of course I could just write:
acts[0] = () => Console.WriteLine(0);
acts[1] = () => Console.WriteLine(1);
acts[2] = () => Console.WriteLine(2);
acts[3] = () => Console.WriteLine(3);
....
But that's not a good approach in my eyey...