我有以下方法,并对编译Expression的性能影响感到好奇。
public async Task<Response<TResult>> Execute<TApi, TResult>(Expression<Func<TApi, Task<TResult>>> executeApiMethod)
{
try
{
var responseData = await executeApiMethod.Compile()(restApi).ConfigureAwait(false);
return new Response<TResult>(responseData);
}
catch (ApiException refitApiException)
{
throw;
}
}
有更好的方法吗? compile()
是否会对性能产生影响,因为这是通用的,每次运行编译时都会用不同的参数调用。