private async Task InvokeAsync(Command command, CommandParameterBuilder builder, object instance) { if (!command.Method.ReturnType.IsLike <Task>()) { command.Method.Invoke(instance, builder.Build()); } else if (command.Method.Invoke(instance, builder.Build()) is Task task) { await task; } }
public async Task InvokeAsync(string input) { if (string.IsNullOrWhiteSpace(input)) { return; } if (FindCommand(input) is var command && command == null) { throw new CommandNotFoundException(); } var instance = _services.GetService(command.Type); var builder = new CommandParameterBuilder(command); builder.TryAddValue(input); builder.TryAddOptions(input); await InvokeAsync(command, builder, instance); }