Beispiel #1
0
        public static string GetTreePath(this ISakiTreeNode sakiTreeNode, string nodesHierarchyDelimeter = TreePathStringDelimeter)
        {
            var node = sakiTreeNode;
            var sb   = new StringBuilder(node.Name);

            node = node.Parent;

            while (node != null)
            {
                sb.Insert(0, $"{node.Name}{nodesHierarchyDelimeter}");
                node = node.Parent;
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public static ISakiTreeNode FindNodeByTreePath(this IEnumerable <ISakiTreeCombinedNode> combinedNodes, string childTreePath, string nodesHierarchyDelimeter = TreePathStringDelimeter)
        {
            var pathParts = childTreePath.Split(new[] { nodesHierarchyDelimeter }, StringSplitOptions.RemoveEmptyEntries);

            if (pathParts.Length == 0)
            {
                return(null);
            }

            var           cn     = combinedNodes?.FirstOrDefault(n => n.Name == pathParts[0]);
            ISakiTreeNode result = cn;

            if (result != null && pathParts.Length > 1)
            {
                result = cn.FindNodeByTreePath(pathParts.Skip(1));
            }

            return(result);
        }
Beispiel #3
0
        public static bool IsDescendantdFor(this ISakiTreeNode node, ISakiTreeCombinedNode combinedNode)
        {
            if (combinedNode == null)
            {
                return(false);
            }
            if (node == null)
            {
                return(false);
            }
            if (node.Parent == null)
            {
                return(false);
            }
            if (node.Parent == combinedNode)
            {
                return(true);
            }

            return(combinedNode.Children
                   ?.Any(c => node.IsDescendantdFor(c as ISakiTreeCombinedNode))
                   ?? false);
        }
Beispiel #4
0
 public static bool HasAscendant(this ISakiTreeNode node, ISakiTreeCombinedNode combinedNode)
 {
     return(!node.IsDescendantdFor(combinedNode));
 }