using System;
using System.Collections.Generic;
namespace Terminal.Gui {
///
/// Implementation of that uses user defined functions
///
public class DelegateTreeBuilder : TreeBuilder {
private Func> childGetter;
private Func canExpand;
///
/// Constructs an implementation of that calls the user
/// defined method to determine children
///
///
///
public DelegateTreeBuilder (Func> childGetter) : base (false)
{
this.childGetter = childGetter;
}
///
/// Constructs an implementation of that calls the user
/// defined method to determine children
/// and to determine expandability
///
///
///
///
public DelegateTreeBuilder (Func> childGetter, Func canExpand) : base (true)
{
this.childGetter = childGetter;
this.canExpand = canExpand;
}
///
/// Returns whether a node can be expanded based on the delegate passed during construction
///
///
///
public override bool CanExpand (T toExpand)
{
return canExpand?.Invoke (toExpand) ?? base.CanExpand (toExpand);
}
///
/// Returns children using the delegate method passed during construction
///
///
///
public override IEnumerable GetChildren (T forObject)
{
return childGetter.Invoke (forObject);
}
}
}