.
This commit is contained in:
@@ -50,6 +50,9 @@ public class Hierarchy<T>
|
||||
|
||||
_hierarchyActions.Enqueue(() =>
|
||||
{
|
||||
if (!Contains(parObj))
|
||||
return;
|
||||
|
||||
var parent = GetParent(parObj);
|
||||
_childrenLookup[parent].Remove(parObj);
|
||||
|
||||
@@ -97,9 +100,24 @@ public class Hierarchy<T>
|
||||
: throw new InvalidOperationException($"Child {parChild} is not in hierarchy");
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetChildren(T? parObj = null)
|
||||
public IEnumerable<T> GetChildren(T? parParent = null)
|
||||
{
|
||||
return _childrenLookup.TryGetValue(parObj, out IList<T>? children) ? children : Enumerable.Empty<T>();
|
||||
return _childrenLookup.TryGetValue(parParent, out var children) ? children : Enumerable.Empty<T>();
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAllChildren(T? parParent = null)
|
||||
{
|
||||
var children = GetChildren(parParent);
|
||||
|
||||
foreach (var child in children)
|
||||
{
|
||||
foreach (var descendant in GetAllChildren(child))
|
||||
{
|
||||
yield return descendant;
|
||||
}
|
||||
|
||||
yield return child;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInHierarchy(T? parAncestor, T? parChild)
|
||||
@@ -133,19 +151,4 @@ public class Hierarchy<T>
|
||||
|
||||
return IsInHierarchy(parAncestor, parent);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAllChildren(T? parObj = null)
|
||||
{
|
||||
IEnumerable<T>? children = GetChildren(parObj);
|
||||
|
||||
foreach (var child in children)
|
||||
{
|
||||
yield return child;
|
||||
|
||||
foreach (var descendant in GetAllChildren(child))
|
||||
{
|
||||
yield return descendant;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user