Converting a group of methods, an anonymous method, or lambda expression to a delegate requires the compiler to know the exact type of delegate. However, you could use lambda expressions and captured variables to make this easier:
public void InvokeMethod(Action action) { action(); } public int Add(int a, int b) { return a + b; } public void Test() { InvokeMethod(() => Add(2, 3)); }
This basically delays the call in the usual way, but by wrapping the actual Add call in a simple Action delegate.
If this does not meet your requirements, perhaps you can tell us a little more about what you are really trying to achieve.
EDIT: If this is generated code, you can apply arguments of the correct type to Func<...> - if there arenβt so many. Other than this, there is no real way to just go through a group of methods. From time to time there were calls to the operator "infoof (...)" (for example, typeof, but for participants), which would provide you with MemberInfo, but this does not actually exist.
Jon Skeet Dec 19 '08 at 8:17 2008-12-19 08:17
source share