From 90be67d6ed1bdca0af69a607190325e572687c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Wed, 4 Sep 2024 15:10:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E6=A0=91FindAllChilds?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0depth=EF=BC=8C=E6=94=AF=E6=8C=81=E4=BB=85?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=8C=87=E5=AE=9A=E6=B7=B1=E5=BA=A6=E5=B1=82?= =?UTF-8?q?=E7=BA=A7=E7=9A=84=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCode/Tree/EntityTree.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/XCode/Tree/EntityTree.cs b/XCode/Tree/EntityTree.cs index 224b5d620..feb847ea7 100644 --- a/XCode/Tree/EntityTree.cs +++ b/XCode/Tree/EntityTree.cs @@ -288,8 +288,9 @@ public static IList FindAllParentsByKey(TKey key) /// 根节点 /// 返回列表是否包含根节点,默认false /// 要排除的节点 + /// 深度。仅返回指定深度层级的节点 /// - protected static IList FindAllChilds(IEntityTree entity, Boolean includeSelf = false, IEntityTree? exclude = null) + public static IList FindAllChilds(IEntityTree entity, Boolean includeSelf = false, IEntityTree? exclude = null, Int32 depth = -1) { if (entity == null) return []; var childlist = entity.Childs; @@ -321,7 +322,7 @@ protected static IList 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]); } } //// 去掉第一个,那是自身