예제 #1
0
            public GroupNode Find(string[] path)
            {
                if (string.Compare(Header, path[0]) == 0 && path.Length == 1)
                {
                    return(this);
                }

                GroupNode child = Children.Find(gn => string.Compare(gn.Header, path[1], true) == 0);

                if (child == null)
                {
                    GroupNode currNode = this;
                    for (int i = 1; i < path.Length; i++)
                    {
                        GroupNode node = new GroupNode(path[i]);
                        currNode.Children.Add(node);
                        currNode = node;
                    }
                    return(currNode);
                }

                return(child.Find(Enumerable.Range(1, path.Length - 1).Select(i => path[i]).ToArray()));
            }
예제 #2
0
        private GroupNode FindNode(string name)
        {
            string[] groupNames = name.Split(Separator).Where(s => !string.IsNullOrEmpty(s.Trim())).Select(s => s.Trim()).ToArray();
            if (groupNames.Length == 0)
            {
                throw new ArgumentException("Invalid grouping name");
            }

            if (_rootNode == null)
            {
                _rootNode = new GroupNode(groupNames[0]);
                GroupNode node = _rootNode;
                for (int i = 1; i < groupNames.Length; i++)
                {
                    GroupNode next = new GroupNode(groupNames[i]);
                    node.Children.Add(next);
                    node = next;
                }
                return(node);
            }

            return(_rootNode.Find(groupNames));
        }