示例#1
0
        static void Main(string[] args)
        {
            var methods = typeof(Program).GetMethods(BindingFlags.Public | BindingFlags.Static)
                          .ToList()
                          .FindAll(x => x.Name.Contains("Experiment_"));

            Dictionary <int, Del>    menuMethods     = new Dictionary <int, Del>();
            Dictionary <int, string> menuMethodNames = new Dictionary <int, string>();

            for (int i = 0; i < methods.Count; i++)
            {
                var method = methods[i];
                menuMethods.Add(i, (Del)Del.CreateDelegate(typeof(Del), methods[i]));
                menuMethodNames.Add(i, methods[i].Name);
            }

            while (true)
            {
                int  selection       = -1;
                bool parseSuccessful = false;
                while (parseSuccessful == false || menuMethods.ContainsKey(selection) == false)
                {
                    Console.Clear();

                    Console.WriteLine("Select:");

                    foreach (var key in menuMethodNames.Keys)
                    {
                        Console.WriteLine(key.ToString() + ": " + menuMethodNames[key] + "\n");
                    }

                    string userInput = Console.ReadLine();
                    parseSuccessful = int.TryParse(userInput, out selection);
                }

                menuMethods[selection].Invoke();

                Console.ReadKey();
            }
        }