/// <summary> /// 所有子级 /// </summary> public static ICollection <T> AllChildren <T>(this ITreeChildren <T> tree) where T : ITreeChildren <T> => GetChildren(tree);
/// <summary> /// 是否是叶子节点 /// </summary> public static bool IsLeaf <T>(this ITreeChildren <T> tree) where T : ITreeChildren <T> => tree.Children?.Count == 0;
/// <summary> /// 递归取出所有下级 /// </summary> /// <param name="t"></param> /// <returns></returns> 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()); }