public IPhonebookCommand GetCommand(string commandString)
        {
            if (!this.commands.ContainsKey(commandString))
            {
                IPhonebookCommand command;
                switch (commandString)
                {
                    case "AddPhone": command = new AddPhoneCommand(); break;
                    case "ChangePhone": command = new ChangePhoneCommand(); break;
                    case "List": command = new ListPhonesCommand(); break;
                    case "Remove": command = new RemovePhoneCommand(); break;
                    default: throw new ArgumentException("Invalid command name");
                }

                this.commands.Add(commandString, command);
            }

            return this.commands[commandString];
        }
Esempio n. 2
0
        public IPhonebookCommand GetCommand(string commandString)
        {
            if (!this.commands.ContainsKey(commandString))
            {
                IPhonebookCommand command;
                switch (commandString)
                {
                case "AddPhone": command = new AddPhoneCommand(); break;

                case "ChangePhone": command = new ChangePhoneCommand(); break;

                case "List": command = new ListPhonesCommand(); break;

                case "Remove": command = new RemovePhoneCommand(); break;

                default: throw new ArgumentException("Invalid command name");
                }

                this.commands.Add(commandString, command);
            }

            return(this.commands[commandString]);
        }