|
@@ -16,7 +16,7 @@ namespace Masuit.Tools.Models
|
|
|
/// <param name="items"></param>
|
|
|
/// <param name="func"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static IEnumerable<T> Filter<T>(this IEnumerable<T> items, Func<T, bool> func) where T : ITree<T>
|
|
|
+ public static IEnumerable<T> Filter<T>(this IEnumerable<T> items, Func<T, bool> func) where T : ITreeChildren<T>
|
|
|
{
|
|
|
var results = new List<T>();
|
|
|
foreach (var item in items.Where(i => i != null))
|
|
@@ -37,9 +37,9 @@ namespace Masuit.Tools.Models
|
|
|
/// <param name="item"></param>
|
|
|
/// <param name="func"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static IEnumerable<T> Filter<T>(this T item, Func<T, bool> func) where T : ITree<T>
|
|
|
+ public static IEnumerable<T> Filter<T>(this T item, Func<T, bool> func) where T : ITreeChildren<T>
|
|
|
{
|
|
|
- return (new[] { item }).Filter(func);
|
|
|
+ return new[] { item }.Filter(func);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -48,7 +48,7 @@ namespace Masuit.Tools.Models
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
/// <param name="items"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static IEnumerable<T> Flatten<T>(this IEnumerable<T> items) where T : ITree<T>
|
|
|
+ public static IEnumerable<T> Flatten<T>(this IEnumerable<T> items) where T : ITreeChildren<T>
|
|
|
{
|
|
|
var result = new List<T>();
|
|
|
foreach (var item in items)
|
|
@@ -62,27 +62,27 @@ namespace Masuit.Tools.Models
|
|
|
/// <summary>
|
|
|
/// 所有子级
|
|
|
/// </summary>
|
|
|
- public static ICollection<T> AllChildren<T>(this ITree<T> tree) where T : ITree<T> => GetChildren(tree);
|
|
|
+ public static ICollection<T> AllChildren<T>(this ITreeChildren<T> tree) where T : ITreeChildren<T> => GetChildren(tree);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 所有父级
|
|
|
/// </summary>
|
|
|
- public static ICollection<T> AllParent<T>(this ITree<T> tree) where T : ITree<T> => GetParents(tree);
|
|
|
+ public static ICollection<T> AllParent<T>(this ITreeParent<T> tree) where T : ITreeParent<T> => GetParents(tree);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否是根节点
|
|
|
/// </summary>
|
|
|
- public static bool IsRoot<T>(this ITree<T> tree) where T : ITree<T> => tree.Parent == null;
|
|
|
+ public static bool IsRoot<T>(this ITreeParent<T> tree) where T : ITreeParent<T> => tree.Parent == null;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否是叶子节点
|
|
|
/// </summary>
|
|
|
- public static bool IsLeaf<T>(this ITree<T> tree) where T : ITree<T> => tree.Children.Count == 0;
|
|
|
+ public static bool IsLeaf<T>(this ITreeChildren<T> tree) where T : ITreeChildren<T> => tree.Children?.Count == 0;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 深度层级
|
|
|
/// </summary>
|
|
|
- public static int Level<T>(this ITree<T> tree) where T : ITree<T> => IsRoot(tree) ? 1 : Level(tree.Parent) + 1;
|
|
|
+ public static int Level<T>(this ITreeParent<T> tree) where T : ITreeParent<T> => IsRoot(tree) ? 1 : Level(tree.Parent) + 1;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 节点路径(UNIX路径格式,以“/”分隔)
|
|
@@ -96,7 +96,7 @@ namespace Masuit.Tools.Models
|
|
|
/// </summary>
|
|
|
/// <param name="t"></param>
|
|
|
/// <returns></returns>
|
|
|
- private static List<T> GetChildren<T>(ITree<T> t) where T : ITree<T>
|
|
|
+ private static List<T> GetChildren<T>(ITreeChildren<T> t) where T : ITreeChildren<T>
|
|
|
{
|
|
|
return t.Children.Union(t.Children.Where(c => c.Children.Any()).SelectMany(tree => GetChildren(tree))).ToList();
|
|
|
}
|
|
@@ -106,7 +106,7 @@ namespace Masuit.Tools.Models
|
|
|
/// </summary>
|
|
|
/// <param name="t"></param>
|
|
|
/// <returns></returns>
|
|
|
- private static List<T> GetParents<T>(ITree<T> t) where T : ITree<T>
|
|
|
+ private static List<T> GetParents<T>(ITreeParent<T> t) where T : ITreeParent<T>
|
|
|
{
|
|
|
var list = new List<T>() { t.Parent };
|
|
|
return t.Parent != null ? list.Union(GetParents(t.Parent)).ToList() : list;
|