Example #1
0
        public static void ChooseMethods(IEnumerable <TestMethodExt> mtds, TestingWindow w)
        {
            w.Start();
            var methods = mtds.ToArray();

again:
            w.WriteLine();
            w.RememberState();
            w.WriteLine("Choose method:");
            for (int i = 0; i < methods.Length; i++)
            {
                w.WriteLine($"{i + 1}: {methods[i].Name}");
            }
            w.Write(">");
            var answ = w.ReadLine();

            if (int.TryParse(answ, out var ch) && ch <= methods.Length && ch > 0)
            {
                methods[ch - 1].InvokeWithConsole();
            }
            else
            {
                w.RestoreState();
                w.WriteLine($"\"{answ}\" is really bad choice! Try again");
                goto again;
            }
        }
Example #2
0
        static void parse2(ParameterInfo p, out object res, out ParseResult o, TestingWindow Window)
        {
            if (p.HasDefaultValue)
            {
                Window.WriteLine($"(default: {p.DefaultValue})");
            }
            Window.Write($"{p.Name}=");
            string answ = Window.ReadLine();

            res = answ;
            if (string.IsNullOrWhiteSpace(answ) && p.HasDefaultValue)
            {
                o = ParseResult.DEFAULT; res = p.DefaultValue; return;
            }
            else if (answ == "$back")
            {
                o = ParseResult.CANCEL; res = null; return;
            }

            o = ParseResult.OK;
            var type = p.ParameterType;

            if (type == typeof(string))
            {
                res = answ; return;
            }
            else if (type == typeof(int))
            {
                if (int.TryParse(answ, out var ire))
                {
                    res = ire; return;
                }
            }
            else if (type == typeof(double))
            {
                if (double.TryParse(answ, out var dre))
                {
                    res = dre; return;
                }
            }
            else if (type == typeof(bool))
            {
                if (bool.TryParse(answ, out var bre))
                {
                    res = bre; return;
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            o = ParseResult.BAD;
        }