[.net] .Net Delegates, binding (closure)

Started by
0 comments, last by Washu 18 years, 7 months ago
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 trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement