コード例 #1
0
        private string Add(IList <string> args)
        {
            var dude   = CommandArguments.Create(args);
            var result = Convert.ToDouble(dude.Command);

            using (var stream = new ArgsGenerator(dude.Arguments))
            {
                foreach (var item in stream)
                {
                    result += Convert.ToDouble(item);
                }
            }
            return(result.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Will invoke the Command Line Interface command with the given arguments.
        /// </summary>
        /// <param name="args">The arguments to feed this Command Line Interface command.</param>
        public void Execute(IList <string> args)
        {
            var    commArgs = CommandArguments.Create(args);
            string result;

            switch (commArgs.Command)
            {
            case "func":
                result = Function(commArgs.Arguments);
                break;

            case "add":
                result = Add(commArgs.Arguments);
                break;

            case "sub":
                result = Subtract(commArgs.Arguments);
                break;

            case "mul":
                result = Multiply(commArgs.Arguments);
                break;

            case "div":
                result = Divide(commArgs.Arguments);
                break;

            case "mod":
                result = Mod(commArgs.Arguments);
                break;

            default:
                result = Function(args);
                break;
            }
            //
            Console.WriteLine(result);
        }
コード例 #3
0
 /// <summary>
 /// Will invoke the Command Line Interface command with the given arguments.
 /// </summary>
 /// <param name="args">The arguments to feed this Command Line Interface command.</param>
 public void Execute(IList <string> args)
 {
     if (args.Count == 0)
     {
         // empty help request
         Console.WriteLine(Help);
     }
     else
     {
         var commArgs = CommandArguments.Create(args);
         var command  = commArgs.Command;
         if (command == "?")
         {
             command = "help";
         }
         var dude = CommandLineInterfaceHelper.GetCommandObject(command);
         if (dude != null)
         {
             Console.WriteLine(dude.Help);
         }
         // missing command object error handled in the GetCommandObject function
     }
 }