コード例 #1
0
        internal MenuDirectoryItem AddMenuDirectoryItem(string name)
        {
            var menuDirectoryItem = new MenuDirectoryItem(name);

            _currentMenuDirectoryItem.Add(menuDirectoryItem);
            _currentMenuDirectoryItem = menuDirectoryItem;

            return(menuDirectoryItem);
        }
コード例 #2
0
        internal MenuDirectoryItem SetCurrentMenuDirectory(string name)
        {
            var menuDirectoryStack = new Stack <MenuDirectoryItem>();

            menuDirectoryStack.Push(Root);

            while (menuDirectoryStack.Any())
            {
                var current = menuDirectoryStack.Pop();

                if (current.Name == name)
                {
                    _currentMenuDirectoryItem = current;
                    return(current);
                }

                foreach (var item in current.Items.OfType <MenuDirectoryItem>())
                {
                    menuDirectoryStack.Push(item);
                }
            }

            throw new InvalidOperationException($"Menu directory '{name}' not found");
        }
コード例 #3
0
 public MenuBuilder(string root)
 {
     Root = new MenuDirectoryItem(root);
     _currentMenuDirectoryItem = Root;
 }