How to call an async method and get a result back without using dynamics
I want to call an async method with reflection. As I figured out there are two ways to do that
await (Task) objType.GetTypeInfo()
.GetDeclaredMethod("ThePrivateMethod")
.Invoke(theObject, null);
or
await (dynamic) objType.GetTypeInfo()
.GetDeclaredMethod("ThePrivateMethod")
.Invoke(theObject, null);
The Problem is if I don’t know the return type I need to do it like in the second example. But my problem is I can't use dynamics in my project. How can I call an async Method without knowing the return type and not using dynamics.
Aucun commentaire:
Enregistrer un commentaire