public interface IBar {
}
public class Bar : IBar {
}
public class Bar2 : IBar {
}
public interface IFoo {
Task<T> Get<T>(T o) where T : IBar;
}
public class Foo : IFoo {
public async Task<T> Get<T>(T o) where T : IBar {
...
}
}
Run Code Online (Sandbox Code Playgroud)
然后我可以使用反射调用此方法:
var method = typeof(IFoo).GetMethod(nameof(IFoo.Get));
var generic = method.MakeGenericMethod(bar2.GetType());
var task = generic.Invoke(foo, new [] { bar2 });
Run Code Online (Sandbox Code Playgroud)
我该如何等待Task?以及如何将其投射到Task<bar2.GetType()>?