private void SetSwitchValues(CommandContext context)
 {
     if (context.Switches != null && context.Switches.Any())
     {
         foreach (var commandSwitch in context.Switches)
         {
             SetSwitchValue(commandSwitch);
         }
     }
 }
        private void Invoke(CommandContext context)
        {
            CheckMethodForSwitches(context.CommandDescriptor.MethodInfo, context.Switches);

            var arguments = (context.Arguments ?? Enumerable.Empty<string>()).ToArray();
            object[] invokeParameters = GetInvokeParametersForMethod(context.CommandDescriptor.MethodInfo, arguments);
            if (invokeParameters == null)
            {
                throw new InvalidOperationException(T("Command arguments \"{0}\" don't match command definition", string.Join(" ", arguments)).ToString());
            }

            this.Context = context;
            var result = context.CommandDescriptor.MethodInfo.Invoke(this, invokeParameters);
            if (result is string)
                context.Output.Write(result);
        }
 public void Execute(CommandContext context)
 {
     SetSwitchValues(context);
     Invoke(context);
 }
 public Task ExecuteAsync(CommandContext context)
 {
     SetSwitchValues(context);
     return InvokeAsync(context);
 }