private async Task <object> InvokeMethodInfoAsync(object instance, MethodInfo methodInfo, IEnumerable <object> arguments, IEnumerable <string> genericArguments, Guid?cancellationTokenGuid) { CancellationToken cancellationToken = default; if (cancellationTokenGuid.HasValue) { var cancellation = new CancellationTokenSource(); cancellationTokenSources.TryAdd(cancellationTokenGuid.Value, cancellation); cancellationToken = cancellation.Token; } var parameters = await BuildExecuteMethodParameters(methodInfo, arguments, cancellationToken); if (genericArguments?.Any() == true) { var arrType = genericArguments.Select(TypeHelper.FindType).ToList(); methodInfo = methodInfo.MakeGenericMethod(arrType.ToArray()); } object result = null; if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(Task)) { await InvokeHelper.InvokeVoidMethodAsync(instance, methodInfo, parameters); } else { result = await InvokeHelper.InvokeMethodAsync <object>(instance, methodInfo, parameters); } if (cancellationTokenGuid.HasValue) { cancellationTokenSources.TryRemove(cancellationTokenGuid.Value, out var token); } return(result); }
public async Task <object> InvokeMethodInfoAsync(object instance, MethodInfo methodInfo, IEnumerable <object> arguments, IEnumerable <string> genericArguments) { var parameters = BuildExecuteMethodParameters(methodInfo, arguments); SetInvokingInstanceProperties(instance); //var enumerable = genericArguments as string[] ?? genericArguments.ToArray(); if (genericArguments?.Any() == true) { var arrType = genericArguments.Select(TypeHelper.FindType).ToList(); methodInfo = methodInfo.MakeGenericMethod(arrType.ToArray()); } if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(Task)) { await InvokeHelper.InvokeVoidMethodAsync(instance, methodInfo, parameters); return(null); } else { return(await InvokeHelper.InvokeMethodAsync <object>(instance, methodInfo, parameters)); } }