TreeBuilder.cs 1.1 KB

123456789101112131415161718192021222324
  1. #nullable disable
  2. namespace Terminal.Gui.Views;
  3. /// <summary>Abstract implementation of <see cref="ITreeBuilder{T}"/>.</summary>
  4. public abstract class TreeBuilder<T> : ITreeBuilder<T>
  5. {
  6. /// <summary>Constructs base and initializes <see cref="SupportsCanExpand"/></summary>
  7. /// <param name="supportsCanExpand">Pass true if you intend to implement <see cref="CanExpand(T)"/> otherwise false</param>
  8. public TreeBuilder (bool supportsCanExpand) { SupportsCanExpand = supportsCanExpand; }
  9. /// <inheritdoc/>
  10. public bool SupportsCanExpand { get; protected set; }
  11. /// <summary>
  12. /// Override this method to return a rapid answer as to whether <see cref="GetChildren(T)"/> returns results. If
  13. /// you are implementing this method ensure you passed true in base constructor or set <see cref="SupportsCanExpand"/>
  14. /// </summary>
  15. /// <param name="toExpand"></param>
  16. /// <returns></returns>
  17. public virtual bool CanExpand (T toExpand) { return GetChildren (toExpand).Any (); }
  18. /// <inheritdoc/>
  19. public abstract IEnumerable<T> GetChildren (T forObject);
  20. }