本文整理汇总了C#中Tree.GetChildren方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.GetChildren方法的具体用法?C# Tree.GetChildren怎么用?C# Tree.GetChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.GetChildren方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Equals
private static bool Equals(Tree thisTree, Tree otherTree) {
if (thisTree == null && otherTree == null) return true;
if (thisTree == null || otherTree == null) return false;
if (thisTree.Title != otherTree.Title) return false;
IEnumerator theseChildren = thisTree.GetChildren().GetEnumerator();
foreach (Tree treeChild in otherTree.GetChildren()) {
if (!theseChildren.MoveNext()) return false;
if (!Equals(theseChildren.Current, treeChild)) return false;
}
return !theseChildren.MoveNext();
}
示例2: ToParseString
public static string ToParseString(Tree theTree) {
var result = new StringBuilder();
if (theTree.Title != null) result.Append(theTree.Title);
int childCount = 0;
foreach (Tree child in theTree.GetChildren()) {
if (childCount == 0) result.Append("<ul>");
result.AppendFormat("<li>{0}</li>", ToParseString(child));
childCount++;
}
if (childCount > 0) result.Append("</ul>");
return result.ToString();
}
示例3: 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>" );
}
示例4: 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 );
}
示例5: Equals
private bool Equals(Parse theParse, Tree theTree)
{
if (theParse == null && theTree == null) return true;
if (theParse == null || theTree == null) return false;
if (GetTitle(theParse) != theTree.Title) return false;
Parse parseChild = Root(theParse).Parts;
foreach (Tree treeChild in theTree.GetChildren()) {
if (!Equals(parseChild, treeChild)) return false;
parseChild = parseChild.More;
}
return (parseChild == null);
}