I have a case where I pass a method name to a function as a string, but I don't want it hard-coded. for example
void MyMethodName()
{
// some code
}
void SomeOtherMethod()
{
SomeExternalLibrary.ExternalClass.FunctionWithStringParameter("MyMethodName");
}
I want something like this:
FunctionWithStringParameter(MyMethodName.ToString());
THis way I can keep track of method calls by "Find All References", and I can use refactoring without worries.
Perhaps the easiest way would be to provide an overload
FunctionWithStringParameter
which can take a delegate as a parameter.The overload could be as simple as:
And call it like this:
To accept methods with different signatures, you'd have to either provide many different overloads, or accept
Delegate
as a parameter, like this:Unfortunately, if you do this, you would have to call it by specifying a delegate type: