![](/img/trans.png)
[英]How to convert delegate `Func<T1, Func<T2, Task<TResult>>>` to `Func<T1, Task<Func<T2, TResult>>`?
[英]Task<T> and Task in Func delegate
我想清理我的一些代码。 我有重载方法。 我能以某种方式简化这段代码并在另一个方法中调用一个方法吗? 无法弄清楚如何做到这一点。
private async Task<T> DecorateWithWaitScreen<T>(Func<Task<T>> action)
{
SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
try
{
return await action();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw;
}
finally
{
SplashScreenManager.CloseForm(false);
}
}
private async Task DecorateWithWaitScreen(Func<Task> action)
{
SplashScreenManager.ShowForm(this, typeof(WaitForm), true, true, false);
try
{
await action();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw;
}
finally
{
SplashScreenManager.CloseForm(false);
}
}
怎么样:
private Task DecorateWithWaitScreen(Func<Task> action)
=> DecorateWithWaitScreen<int>(async () => { await action(); return 0; });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.