Esempio n. 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);
        }
        public ISelectionItem <T> AddChild(T item)
        {
            var node = new ListPromptItem <T>(item, this);

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

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

            return(level);
        }
Esempio n. 5
0
 public void Add(ListPromptItem <T> node)
 {
     _roots.Add(node);
 }