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 void Run() { while (true) { string input = Console.ReadLine(); string output = command.Read(input); Console.WriteLine(output); } HelloCommand hc = new HelloCommand(); Console.WriteLine(hc.GetType().FullName); }
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; }
public CommandInterpreter() { Command = new HelloCommand(); }