Используя отражение, я я могу получить нужные мне методы, и теперь я хочу вызвать этот метод.
Проблема: я не могу получить данные путем вызова. Проблема, похоже, в отсутствии у меня знаний асинхронного программирования.
Пока мой метод выглядит так:
Код: Выделить всё
public static async Task RunMethodAsync(TClass Class,MethodInfo method, params object[] param)
{
try
{
Task task = (Task)method.Invoke(Class, param);
// Await the task to get the result
await task.ConfigureAwait(false);
// Retrieve the result from the Task
var resultProperty = task.GetType().GetProperty("Result");
TReturn result = (TReturn)resultProperty.GetValue(task);
return result;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Код: Выделить всё
TReturnКакова будет конечная цель заключается в запуске моего метода, используя:
Код: Выделить всё
Task[] tasks = new Task[]{Task.Run(() => connectorHelper.pullDataToDataLake(connectorService, method, new object[] { }, filPath))
public async Task pullDataToDataLake(TService service,MethodInfo method, object[] param, string filPath = "")
{
try
{
object obj = await ReflectionHelper.RunMethodAsync(service, method, param);
await UploadModelToBlob(obj, filPath);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... reflection