/// <summary>
        /// Add custom task
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="key"></param>
        /// <param name="title"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static ConsoleMenu Add(this ConsoleMenu menu, ConsoleKey key, string title, Func <Task> action, bool waitForCompletion = true)
        {
            var item = new ConsoleMenuItem(key, title, action, waitForCompletion);

            menu.Add(item);
            return(menu);
        }
        /// <summary>
        /// Add menu item from class which implements IConsoleTask
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="task"></param>
        /// <param name="waitForCompletion"></param>
        /// <returns></returns>
        public static ConsoleMenu Add(this ConsoleMenu menu, IConsoleTask task, bool waitForCompletion = true, string overrideTitle = null, ConsoleKey?overrideKey = null)
        {
            var key   = overrideKey ?? ConsoleKey.A + menu.ItemCount;
            var title = overrideTitle ?? task.Title;

            if (string.IsNullOrWhiteSpace(title))
            {
                title = task.GetType().Name.FromCamelCaseToSentence();
            }

            var item = new ConsoleMenuItem(
                key,
                title,
                () => menu.RunTask(task.Execute()),
                waitForCompletion);

            menu.Add(item);
            return(menu);
        }
Example #3
0
 public void Add(ConsoleMenuItem item)
 {
     _items.Add(item);
 }