本文整理汇总了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 );
}
示例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>" );
}