private static void MainLoop() { int choiceIndex = 0; string[] choices = new string[] { "Sandbox", "Variables", "Help", "Documentation", "Settings", "Quit" }; choiceIndex = EnterChoiceIndex(choices, choiceIndex); while (choiceIndex >= 0) { Console.CursorVisible = false; string choice = choices[choiceIndex]; switch (choice) { case "Sandbox": Sandbox.SandboxLoop(true); break; case "Variables": Sandbox.VariableLoop(); break; case "Help": Help(); break; case "Documentation": Documentation(); break; case "Settings": Settings(); break; case "Quit": return; default: //null choice return; } Console.Clear(); choiceIndex = EnterChoiceIndex(choices, choiceIndex); } }
private static void UseFunction(string funcChoice) { //get the function itself System.Reflection.MethodInfo mi = Function.GetFunctionFromFullName(funcChoice); string funcName = mi.Name; //get the parameters so we know what to ask System.Reflection.ParameterInfo[] pis = mi.GetParameters(); object[] args = new object[pis.Length]; Clear(); //LINE 1: Preview of function //LINE 2: Instructions //LINE 3: Input int argsEntered = 0; while (argsEntered < args.Length) { Type t = pis[argsEntered].ParameterType; Console.SetCursorPosition(0, 0); PrintPartialFunction(funcName, args); Console.SetCursorPosition(0, 1); Console.Write(string.Format("Enter a {0}.{1}", t.Name.ToLower(), new string(' ', 30)));//write the instructions Console.SetCursorPosition(0, 2); object input = null; if (t == typeof(string)) { input = EnterString(); } else if (t == typeof(MathNet.Symbolics.SymbolicExpression)) { input = EnterExpression(); } else if (t.IsArray) { input = ParseDoubleArray(EnterString()); } else if (t == typeof(int)) { input = EnterInt(); } else if (t == typeof(double)) { input = EnterDouble(); } else if (t == typeof(bool)) { input = EnterBool(); } else { input = EnterString(); } args[argsEntered++] = input; Console.SetCursorPosition(0, 2); Console.Write(new string(' ', input.ToString().Length + 1)); } //input is done, print the output info and then go into sanbox mode Clear(); object output = Function.EvaluateFunction(funcName, args); Sandbox.SetVariable("ans", output); PrintPartialFunction(funcName, args); PrintLine(); Print(string.Format("ans = {0}", output)); Print("Use ans to refer to your answer."); PrintLine(2); Sandbox.SandboxLoop(false); }