Streamline tree API a bit

This commit is contained in:
Patrik Svensson
2021-01-02 10:47:29 +01:00
committed by Patrik Svensson
parent b136d0299b
commit 4bfb24bfcb
13 changed files with 245 additions and 228 deletions

View File

@ -0,0 +1,27 @@
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IHasCulture"/>.
/// </summary>
public static class HasTreeNodeExtensions
{
/// <summary>
/// Adds a child to the end of the node's list of children.
/// </summary>
/// <typeparam name="T">An object type with tree nodes.</typeparam>
/// <param name="obj">The object that has tree nodes.</param>
/// <param name="child">Child to be added.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T AddChild<T>(this T obj, TreeNode child)
where T : class, IHasTreeNodes
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Children.Add(child);
return obj;
}
}
}