Beispiel #1
0
                static List <int> GetMyPath(MyGenericTreeNode <T> node)
                {
                    if (node.IsRoot)
                    {
                        if (node is Tree <Dictionary <string, string> > )
                        {
                            return(new List <int>());
                        }
                        else
                        {
                            return new List <int> {
                                       1
                            }
                        };
                    }
                    else
                    {
                        var path = GetMyPath((MyGenericTreeNode <T>)node.Parent);

                        var nodeIndex = node.Parent.Children.Where(n => (n as MyGenericTreeNode <T>).Type == node.Type).ToList().IndexOf(node) + 1;

                        path.Add(nodeIndex);

                        return(path);
                    }
                }
Beispiel #2
0
        public void InheritedGenericTreeNode()
        {
            var node1 = new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1" },
                { "ExpectedPath", "1" }
            }, MyTreeNodeType.Folder);

            var node1_1 = node1.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1-1" },
                { "ExpectedPath", "1-1" }
            }, MyTreeNodeType.Leaf));

            var node1_2 = node1.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1-2" },
                { "ExpectedPath", "1-2" }
            }, MyTreeNodeType.Leaf));

            var node11 = node1.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.1" },
                { "ExpectedPath", "1.1" }
            }, MyTreeNodeType.Folder));

            var node11_1 = node11.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.1-1" },
                { "ExpectedPath", "1.1-1" }
            }, MyTreeNodeType.Leaf));

            var node11_2 = node11.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.1-2" },
                { "ExpectedPath", "1.1-2" }
            }, MyTreeNodeType.Leaf));

            var node111 = node11.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.1.1" },
                { "ExpectedPath", "1.1.1" }
            }, MyTreeNodeType.Folder));

            var node111_1 = node111.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.1.1-1" },
                { "ExpectedPath", "1.1.1-1" }
            }, MyTreeNodeType.Leaf));

            var node111_2 = node111.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.1.1-2" },
                { "ExpectedPath", "1.1.1-2" }
            }, MyTreeNodeType.Leaf));

            var node12 = node1.AddChild(new MyGenericTreeNode <Dictionary <string, string> >(new Dictionary <string, string> {
                { "Name", "node1.2" },
                { "ExpectedPath", "1.2" }
            }, MyTreeNodeType.Folder));

            var nodes = node1.ToList();

            nodes.Should().HaveCount(10);

            foreach (var node in nodes)
            {
                node.PathString.Should().Be(node.Value["ExpectedPath"]);
            }
        }