public void Execute(CommandContext context) { SetSwitchValues(context); Invoke(context); }
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); }
private void SetSwitchValues(CommandContext context) { if (context.Switches != null && context.Switches.Any()) { foreach (var commandSwitch in context.Switches) { SetSwitchValue(commandSwitch); } } }