C# 反射调用异步方法
private async Task<object?> InvokeAsync(string method, params object[] parameters)
{
var task = service.GetType().InvokeMember(method, BindingFlags.InvokeMethod, null, service, parameters) as Task;
if (task != null) await task;
var result = task?.GetType().GetProperty("Result")?.GetValue(task);
return result;
}
原文链接:https://justsimplycode.com/2020/05/10/dynamically-call-an-async-generic-method-using-reflection/