本文整理汇总了C#中Tree.GetDepth方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.GetDepth方法的具体用法?C# Tree.GetDepth怎么用?C# Tree.GetDepth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.GetDepth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: bindPages
private void bindPages( List<Page> list )
{
Tree<Page> tree = new Tree<Page>( list );
IBlock block = getBlock( "list" );
foreach (Page data in tree.GetAllOrdered()) {
block.Set( "data.Id", data.Id );
block.Set( "data.OrderId", data.OrderId );
block.Set( "data.AddSubLink", to( AddSubPage, data.Id ) );
int indentLength = tree.GetDepth( data.Id ) * 20;
String indent = "padding-left:" + indentLength + "px";
block.Set( "data.Indent", indent );
block.Set( "data.Title", data.Title );
block.Set( "data.Created", data.Created );
block.Set( "data.Hits", data.Hits );
block.Set( "data.ReplyCount", data.Replies );
block.Set( "data.IsAllowReplyStr", data.IsAllowReplyStr );
block.Set( "data.ViewUrl", to( ViewUrl, data.Id ) );
block.Set( "data.LinkShow", plink( data.Id ) );
block.Set( "data.LinkDelete", to( Delete, data.Id ) );
block.Set( "data.LinkEdit", to( Edit, data.Id ) );
block.Next();
}
}
示例2: 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 );
}