I need to be able to pass an arbitrary method to some function myFunction
:
void myFunction(AnyFunc func) { ... }
It should be possible to execute it with other static, instance, public or private methods or even delegates:
myFunction(SomeClass.PublicStaticMethod);
myFunction(SomeObject.PrivateInstanceMethod);
myFunction(delegate(int x) { return 5*x; });
Passed method may have any number of parameters and any return type. It should also be possible to learn the actual number of parameters and their types in myFunction
via reflection. What would be AnyFunc
in the myFunction
definition to accommodate such requirements? It is acceptible to have several overloaded versions of the myFunction
.