static void MainLoop() { bool pContinue = true; while (pContinue) { Console.Write(m_prompt); string input = Console.ReadLine(); if (input == string.Empty) { Console.Clear(); continue; } var command = new HostCommand(input); switch (command.MethodName) { case "exit": case "quit": pContinue = false; break; default: ExecuteCommand(command); break; } Console.WriteLine(""); } }
static bool ValidateCommand(HostCommand cmd) { if (!_methodDictionary.ContainsKey(cmd.MethodName)) { return(false); } return(true); }
static void ExecuteCommand(HostCommand cmd) { try { // Validate The Passed in Command if (!ValidateCommand(cmd)) { Console.WriteLine("{0} is an invalid command", cmd.MethodName); Help(); return; } // Make sure the user provided the correct number of arguments MethodDetails methodDetails = _methodDictionary[cmd.MethodName]; if (!ValidateParameters(methodDetails, cmd.Arguments.Count())) { return; } object[] inputs = GetMethodParams(methodDetails, cmd.Arguments); InvokeMethod(methodDetails, inputs); } catch (Exception e) { Console.WriteLine(); WriteExceptions(e); if (e.InnerException != null) { Console.WriteLine(); WriteExceptions(e.InnerException); } } }