当前位置: 首页>>代码示例>>C#>>正文


C# Tree.GetRoots方法代码示例

本文整理汇总了C#中Tree.GetRoots方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.GetRoots方法的具体用法?C# Tree.GetRoots怎么用?C# Tree.GetRoots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree.GetRoots方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testTreeData

        public void testTreeData()
        {
            List<Node> nodes = getNodesAll();

            Tree<Node> tree = new Tree<Node>( nodes );

            // GetById
            INode node = tree.GetById( 13 );
            Assert.IsNotNull( node );
            Assert.AreEqual( "node13", node.Name );

            INode nullNode = tree.GetById( 9999 );
            Assert.IsNull( nullNode );

            // GetParent
            INode parent = tree.GetParent( node.Id );
            Assert.IsNotNull( parent );
            Assert.AreEqual( 5, parent.Id );

            // GetDepth
            Assert.AreEqual( 0, tree.GetDepth( 2 ) );
            Assert.AreEqual( 1, tree.GetDepth( 7 ) );
            Assert.AreEqual( 2, tree.GetDepth( 13 ) );
            Assert.AreEqual( 2, tree.GetDepth( 14 ) );

            // GetPath
            List<Node> path = tree.GetPath( 13 );
            Assert.AreEqual( 3, path.Count );

            Assert.AreEqual( 1, path[0].Id );
            Assert.AreEqual( 5, path[1].Id );
            Assert.AreEqual( 13, path[2].Id );

            // GetChildren
            Assert.AreEqual( 0, tree.GetChildren( 4 ).Count );
            Assert.AreEqual( 0, tree.GetChildren( 7 ).Count );

            List<Node> children = tree.GetChildren( 5 );
            Assert.AreEqual( 3, children.Count );
            Assert.AreEqual( 13, children[0].Id );
            Assert.AreEqual( 14, children[1].Id );
            Assert.AreEqual( 15, children[2].Id );

            // GetRoots
            List<Node> roots = tree.GetRoots();
            Assert.AreEqual( 3, roots.Count );
            Assert.AreEqual( 1, roots[0].Id );
            Assert.AreEqual( 2, roots[1].Id );
            Assert.AreEqual( 3, roots[2].Id );
        }
开发者ID:bae2014,项目名称:wojilu,代码行数:50,代码来源:TreeTest.cs

示例2: addLocationMenu

        private static void addLocationMenu( StringBuilder sb, MvcContext ctx ) {

            sb.Append( "<ul class=\"dropdown-menu\" id=\"locationBoards\">" );

            ForumBoardService service = new ForumBoardService();
            Tree<ForumBoard> tree = new Tree<ForumBoard>( service.GetBoardAll( ctx.app.Id, ctx.viewer.IsLogin ) );
            List<ForumBoard> categories = tree.GetRoots();

            foreach (ForumBoard category in categories) {
                sb.AppendFormat( "<li class=\"forum_location_category\">{0}</li>", category.Name );
                sb.Append( "<li class=\"forum_location_forums\">" );
                List<ForumBoard> children = tree.GetChildren( category.Id );
                foreach (ForumBoard board in children) {
                    sb.AppendFormat( "<a href=\"{0}\">{1}</a> ", alink.ToAppData( board ), board.Name );
                }
                sb.Append( "</li>" );
            }
            sb.Append( "</ul>" );
        }
开发者ID:2014AmethystCat,项目名称:wojilu,代码行数:19,代码来源:ForumLocationUtil.cs


注:本文中的Tree.GetRoots方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。