buunguyen / fasterflect

.NET Reflection Made Fast and Simple ⛺
https://www.nuget.org/packages/fasterflect/
Apache License 2.0
283 stars 55 forks source link

async Task method how to await #23

Open znyet opened 2 years ago

znyet commented 2 years ago
public class Test
{
    public static async Task<string> Add(string name)
    {
        await Task.Delay(1000);
        return "hello" + name;
    }

    public static async Task<int> Count()
    {
        await Task.Delay(1000);
        return 1;
    }
}

 var type = typeof(Test);
object m1 = type.CallMethod("Add", "Job");
object m2 = type.CallMethod("Count");

how to await m1 and m2 ?

Task<string> task1 = m1 as Task<string>;
Task<int> task2 = m2 as Task<int>;
Although this can be done

but how to do like common..

object val = await m1 ? object val2 = await m2 ?

because i need the object value...