/// <summary> /// Initializes a new instance of the <see cref="T:dbTask.MenuTreeNode"/> class. /// </summary> /// <param name="parent">Parent.</param> /// <param name="decisions">Decisions.</param> /// <param name="nodeMenu">Node menu.</param> /// <param name="onPromptAction">On prompt action.</param> public MenuTreeNode(MenuTreeNode parent, IDictionary <int, Func <MenuTreeNode> > decisions, string nodeMenu, Action onPromptAction = null) { Parent = parent; NodeMenu = nodeMenu; Decisions = decisions; OnPromptAction = onPromptAction ?? (() => Console.WriteLine(NodeMenu)); }
/// <summary> /// Begins the tree traversing. /// </summary> /// <param name="node">Node.</param> public void BeginTreeTraversing(MenuTreeNode node) { node.OnPromptAction(); if (!(node.Decisions is null)) { int decision = Reader.Read <int>("Enter command", "Smth wrong, reenter", el => node.Decisions.ContainsKey(el)); BeginTreeTraversing(node.Decisions[decision]?.Invoke() ?? node); }
/// <summary> /// Initializes a new instance of the <see cref="T:dbTask.MenuTree"/> class. /// </summary> /// <param name="root">Root.</param> public MenuTree(MenuTreeNode root) { Root = root; }