Search code examples
c#stringreflectionsignaturemethodinfo

Get MethodInfo Signature


Say you have a MethodInfo relating to the method myMethod:

void myMethod(int param1, int param2) { }

and you want to create a string that represents the method's signature:

string myString = "myMethod (int, int)";

Looping through the MethodInfo parameters, I was able to achieve these results by calling the parameter types' ToString methods:

"myMethod (System.Int32, System.Int32)"

How can I improve on this and produce the results shown above?


Solution

  • This question has been asked before, and it can done through the CodeDom api. See this and this. Note that those keywords (int, bool, etc.) are language specific, so if you are outputting this for a general .NET consumer the framework type names are usually preferred.