コード例 #1
0
                static List <int> GetMyPath(MyTypedTreeNode 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((MyTypedTreeNode)node.Parent);

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

                        path.Add(nodeIndex);

                        return(path);
                    }
                }
コード例 #2
0
        public void InheritedTypedTreeNode()
        {
            var node1 = new MyTypedTreeNode(new Dictionary <string, string> {
                { "Name", "node1" },
                { "ExpectedPath", "1" }
            }, MyTreeNodeType.Folder);

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

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

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

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

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

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

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

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

            var node12 = node1.AddChild(new MyTypedTreeNode(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"]);
            }
        }