I want to write a method in C# that can take any other method and print out info about this method, like name, parameters etc. Something like:
public string GetMethodInfo([some type] method, params object[] args)
{
// Use reflection to create a string with the method's name and list of parameters with their values
//...
return methodText;
}
public int Foo(int a, int b)
{
return a + b;
}
public void DoSomething(int a, int b, int c)
{
Debug.WriteLine("Now calling... " + GetMethodInfo(Foo, a, b));
Foo(a, b);
//...
}
No matter what Type I use (even "object"), the compiler always complains that it can't convert it from "method group". I understand that method group is not a real Type but simply a compiler construct that means something along the lines of "a group of one of more methods, which will be overloaded if there are more than one". Note though that in this case the method I'm passing in will never have any overloads so I should be able to resolve it in GetMethodInfo (and even if there are overloads, it should be possible to resolve it from the list of passed in args).
But is there no way to pass in a method of arbitrary signature that can then be analyzed using reflection? Of course I can make a delegate declaration for each method and use overloaded GetMethoInfo methods but that defeats the purpose.
Add your 2¢