private async Task ExecuteActionRouteAsync(CliActionContext context) { var controller = context.ActionRoute !.ControllerType.CreateInstance <object>(_serviceProvider); var actionArguments = CreateActionArguments(context); var result = context.ActionRoute.ActionMethod.Invoke(controller, actionArguments); var isVoid = context.ActionRoute.ActionMethod.ReturnType == typeof(void); if (result == null && !isVoid) { throw new ActionReturnValueNullException(); } if (isVoid) { return; } var resultType = result !.GetType(); if (resultType == typeof(Task <CliActionResult>)) { var actionResult = await(Task <CliActionResult>) result; context.ReturnCode = actionResult.ReturnCode; return; } if (resultType == typeof(Task <int>)) { var returnCode = await(Task <int>) result; context.ReturnCode = returnCode; return; } if (result is Task taskResult) { await taskResult; return; } if (resultType == typeof(int)) { context.ReturnCode = (int)result; return; } if (resultType != typeof(CliActionResult)) { throw new ActionReturnTypeNotSupportedException(resultType); } context.ReturnCode = ((CliActionResult)result).ReturnCode; }