<分区>
我在 C# 中使用一个库,其中一个方法要求我将目标方法的字符串名称作为参数传递。
出于显而易见的原因,我想避免使用硬编码字符串,因此我将编写一个中间 util 方法,它接受一个方法,获取名称(可能通过反射)并将其提供给库方法。
我希望中间方法看起来像这样:
public void CallOtherMethod(???? inputMethod)
{
string methodName = inputMethod.Name; // This gives me the method without the namespace, right?
this.CallFinalMethod(methodName);
}
这样调用:
this.CallOtherMethod(this.SomeOtherMethod);
但是,我在确定执行此操作所需的类型时遇到了一些麻烦。
如何正确定义我的方法?
附带说明一下,我很乐意将其作为库的扩展方法编写,但这与库的行为方式不太相符。