【发布时间】:2021-04-02 17:02:59
【问题描述】:
有没有办法从通用动作委托中的调用方法中获取结果?
代码执行
public string TestRun()
{
ExecuteService<SomeClass>(e => e.ExecuteMethod(), out var result);
return result; // return the value;
}
类方法
public class SomeClass
{
public string ExecuteMethod()
{
return "Hello!?";
}
}
执行通用动作委托的方法
protected internal void ExecuteService<TAction>(Action<TAction> action, out Response response) where TAction : new()
{
action?.Invoke(new TAction()); // invoke
response = action?.something() // problem... how to get the value from this point forward
}
如何在动作委托ExecuteService<> 方法中从该方法ExecuteMethod() 获取返回值并将其分配给out 值?这可以实现吗?
【问题讨论】:
标签: c# delegates inversion-of-control