示例#1
0
        public string Read(string args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("Value cannot be null!");
            }

            var value = args.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();

            var commandName = value[0];

            if (commandName == "Hello".ToLower())
            {
                var commandArgs = value.Skip(1).ToArray();

                HelloCommand command = new HelloCommand();
                return(command.Execute(commandArgs));
            }
            else if (commandName == "Exit".ToLower())
            {
                ExitCommand command = new ExitCommand();
                return(command.Execute(null));
            }
            else
            {
                throw new InvalidOperationException("Invalid command!");
            }
        }
        public string Read(string args)
        {
            string[] commandArgs = args.Split().Skip(1).ToArray();
            string commandType = args.Split()[0];
            string result = null;
            if (commandType == "Hello")
            {
                ICommand command = new HelloCommand();
                result = command.Execute(commandArgs);
            }
            else if (commandType == "Exit")
            {
                ICommand command = new ExitCommand();
                result = command.Execute(commandArgs);
            }

            return result;
        }