Пример #1
0
        /// <summary>
        /// Adds a choice.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <returns>A <see cref="ISelectionItem{T}"/> so that multiple calls can be chained.</returns>
        public ISelectionItem <T> AddChoice(T item)
        {
            var node = new ListPromptItem <T>(item);

            _tree.Add(node);
            return(node);
        }
Пример #2
0
        public ISelectionItem <T> AddChild(T item)
        {
            var node = new ListPromptItem <T>(item, this);

            Children.Add(node);
            return(node);
        }
Пример #3
0
 public ListPromptItem(T data, ListPromptItem <T>?parent = null)
 {
     Data     = data;
     Parent   = parent;
     Children = new List <ListPromptItem <T> >();
     Depth    = CalculateDepth(parent);
 }
Пример #4
0
        private static int CalculateDepth(ListPromptItem <T>?parent)
        {
            var level = 0;

            while (parent != null)
            {
                level++;
                parent = parent.Parent;
            }

            return(level);
        }
Пример #5
0
 public void Add(ListPromptItem <T> node)
 {
     _roots.Add(node);
 }