TreeBuilder.cs 1.2 KB

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