Updating a hierarchy path
static void GeneratePath(List<HierarchyNode> all, HierarchyNode current)
{
string path = "";
Action<List<HierarchyNode>, HierarchyNode> GetPath = null;
GetPath = (List<HierarchyNode> ps, HierarchyNode p) => {
var parents = all.Where(x => x.HierarchyNodeId == p.ParentNodeId);
foreach (var parent in parents)
{
path += $"/{ parent.Name}";
GetPath(ps, parent);
}
};
GetPath(all, current);
string[] split = path.Split(new char[] { '/' });
Array.Reverse(split);
current.Path = string.Join(" > ", split) + current.Name;
}
No comments:
Post a Comment