Skip to content

Commit

Permalink
实体树FindAllChilds增加depth,支持仅返回指定深度层级的节点
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 4, 2024
1 parent 0b24d1f commit 90be67d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions XCode/Tree/EntityTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ public static IList<TEntity> FindAllParentsByKey(TKey key)
/// <param name="entity">根节点</param>
/// <param name="includeSelf">返回列表是否包含根节点,默认false</param>
/// <param name="exclude">要排除的节点</param>
/// <param name="depth">深度。仅返回指定深度层级的节点</param>
/// <returns></returns>
protected static IList<TEntity> FindAllChilds(IEntityTree entity, Boolean includeSelf = false, IEntityTree? exclude = null)
public static IList<TEntity> FindAllChilds(IEntityTree entity, Boolean includeSelf = false, IEntityTree? exclude = null, Int32 depth = -1)
{
if (entity == null) return [];
var childlist = entity.Childs;
Expand Down Expand Up @@ -321,7 +322,7 @@ protected static IList<TEntity> FindAllChilds(IEntityTree entity, Boolean includ
// 已进入待处理队列的,不再处理
if (stack.Contains(childs[i])) continue;

stack.Push(childs[i]);
if (depth < 0 || childs[i].Deepth <= depth) stack.Push(childs[i]);
}
}
//// 去掉第一个,那是自身
Expand Down

0 comments on commit 90be67d

Please sign in to comment.