TreeBuilder.cs 1.1 KB

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