[.net] .Net Delegates, binding (closure)
I'm experimenting with .Net delegates, and it's not clear to me how you wedge a method into a delegate that has a different signature. What's the hack for closure? How do you bind parameters?
e.g.
I have a delegate that's void delegate(void) and I want to take Test::Insert(int x, int y) and put that in the delegate. How do I bind the Test object reference, and how do I bind the x & y parameters?
e.g. in C++ you'd do something like
typedef boost::function<void (void)> Action;
Test* t = new Test;
Action action = boost::bind(&Test::Insert, *t, 4, 5);
action();
The simple answer is: You don't. A more complex answer: use a proxy object that stores a delegate to the function you want to call along with the parameters you want to pass and then have it hold a void(void) function that is passed to the delegate.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement