本文整理汇总了C#中Tree.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.AddChild方法的具体用法?C# Tree.AddChild怎么用?C# Tree.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.AddChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var tree = new Tree<string>("grandparent");
tree.AddChild(new Tree<string>("parent")
.AddChild("child1")
.AddChild("child2")
.AddChild(new Tree<string>("child3")
.AddChild("grandchild of 3(1)")
.AddChild("grandchild of 3(2)")))
.AddChild("kuzman");
var iterator = new Treeterator<string>(tree);
while(!iterator.Finished)
{
Console.WriteLine(iterator.Next);
}
// or
Console.WriteLine("\n\n");
foreach (var item in tree)
{
Console.WriteLine(item);
}
}
示例2: LoadTreeFromBattleObject
private void LoadTreeFromBattleObject(Game game, BattleObject activeBattleObject)
{
Tree<string> optionTree = new Tree<string>("root");
optionTree.AddChild("Attack");
foreach(var attack in activeBattleObject.AttackList) {
optionTree.GetFirstChild("Attack").AddChild(attack);
}
optionTree.AddChild("Magic");
foreach(var magic in activeBattleObject.MagicList) {
optionTree.GetFirstChild("Magic").AddChild(magic);
}
optionTree.AddChild("Item");
foreach(var item in activeBattleObject.ItemList) {
optionTree.GetFirstChild("Item").AddChild(item);
}
_menuItemView.SetTree(optionTree);
_menuItemView.SetFirstSelected();
}
示例3: GetSolutionFoldersTree
public static Tree GetSolutionFoldersTree(DTE dte)
{
var tree = new Tree();
var projects = (dte.Solution as Solution2)?.Projects;
if (projects == null) return tree;
foreach (Project project in projects)
{
if (project?.Kind != ProjectKinds.vsProjectKindSolutionFolder) continue;
var node = new Node(project.Name);
var subProjects = project.ProjectItems.Cast<ProjectItem>().Select(p => new ProjectNode(p));
node.AddChilds(subProjects);
tree.AddChild(node);
}
return tree;
}
示例4: Traverse
static void Traverse(string startingDirectory, Tree<Folder> root)
{
var dirs = new DirectoryInfo(startingDirectory).GetDirectories();
foreach (var dir in dirs)
{
var childNode = new Tree<Folder>(new Folder(dir.Name));
var files = dir.GetFiles();
foreach (var file in files)
{
childNode.Value.AddFile(new File(file.Name, (int)file.Length));
}
root.AddChild(childNode);
Traverse(dir.FullName, childNode);
}
}
示例5: AddProjectsToTree
public static void AddProjectsToTree(Solution solution,ref Tree tree)
{
var projects = solution.Projects.ToList();
var allreadyAddedProjects = tree.DescendantNodes().OfType<ProjectNode>().ToList();
foreach (var project in projects)
{
var existingProject = allreadyAddedProjects.WithName(project.Name);
if (existingProject != null)
{
existingProject.Documents = project.Documents.ToList();
}
else
{
existingProject = new ProjectNode(project);
tree.AddChild(existingProject);
}
}
}
示例6: GetTreeFromInputStream
private Tree GetTreeFromInputStream()
{
int wordIndex = 0;
// FSA
//label:
while (tokenizer.HasNext())
{
string token = tokenizer.Next();
switch (token)
{
case LeftParen:
// cdm 20100225: This next line used to have "" instead of null, but the traditional and current tree normalizers depend on the label being null not "" when there is no label on a tree (like the outermost English PTB level)
string label = (tokenizer.Peek().Equals(LeftParen)) ? null : tokenizer.Next();
if (RightParen.Equals(label))
{
//Skip past empty trees
continue;
}
else if (treeNormalizer != null)
{
label = treeNormalizer.NormalizeNonterminal(label);
}
if (label != null)
{
label = StarPattern.Replace(label, "*");
label = SlashPattern.Replace(label, "/");
}
Tree newTree = treeFactory.NewTreeNode(label, null); // dtrs are added below
if (currentTree == null)
stack.Add(newTree);
else
{
currentTree.AddChild(newTree);
stack.Add(currentTree);
}
currentTree = newTree;
break;
case RightParen:
if (!stack.Any())
{
// Warn that file has too many right parens
//break label;
goto post_while_label;
}
//Accept
currentTree = stack.Last();
stack.RemoveAt(stack.Count - 1); // i.e., stack.pop()
if (!stack.Any()) return currentTree;
break;
default:
if (currentTree == null)
{
// A careful Reader should warn here, but it's kind of useful to
// suppress this because then the TreeReader doesn't print a ton of
// messages if there is a README file in a directory of Trees.
//break label;
goto post_while_label;
}
string terminal = (treeNormalizer == null) ? token : treeNormalizer.NormalizeTerminal(token);
terminal = StarPattern.Replace(terminal, "*");
terminal = SlashPattern.Replace(terminal, "/");
Tree leaf = treeFactory.NewLeaf(terminal);
if (leaf.Label() is IHasIndex)
{
var hi = (IHasIndex) leaf.Label();
hi.SetIndex(wordIndex);
}
if (leaf.Label() is IHasWord)
{
var hw = (IHasWord) leaf.Label();
hw.SetWord(leaf.Label().Value());
}
wordIndex++;
currentTree.AddChild(leaf);
// cdm: Note: this implementation just isn't as efficient as the old recursive descent parser (see 2008 code), where all the daughters are gathered before the tree is made....
break;
}
}
post_while_label:
{
}
//Reject
return null;
}
示例7: TransformCc
/// <summary>
/// If things match, this method destructively changes the children list
/// of the tree t. When this method is called, t is an NP and there must
/// be at least two children to the right of ccIndex.
/// </summary>
/// <param name="t">The tree to transform a conjunction in</param>
/// <param name="ccIndex">The index of the CC child</param>
/// <returns>t</returns>
private static Tree TransformCc(Tree t, int ccIndex)
{
// use the factories of t to create new nodes
ITreeFactory tf = t.TreeFactory();
ILabelFactory lf = t.Label().LabelFactory();
Tree[] ccSiblings = t.Children();
//check if other CC
var ccPositions = new List<int>();
for (int i = ccIndex + 1; i < ccSiblings.Length; i++)
{
if (ccSiblings[i].Value().StartsWith(PartsOfSpeech.CoordinatingConjunction) && i < ccSiblings.Length - 1)
{
// second conjunct to ensure that a CC we add isn't the last child
ccPositions.Add(i);
}
}
// a CC b c ... -> (a CC b) c ... with b not a DT
string beforeSibling = ccSiblings[ccIndex - 1].Value();
if (ccIndex == 1 &&
(beforeSibling == PartsOfSpeech.Determiner
|| beforeSibling == PartsOfSpeech.Adjective
|| beforeSibling == PartsOfSpeech.Adverb
|| !(ccSiblings[ccIndex + 1].Value() == PartsOfSpeech.Determiner))
&& !(beforeSibling.StartsWith("NP")
|| beforeSibling.Equals("ADJP")
|| beforeSibling == PartsOfSpeech.NounPlural))
{
// && (ccSiblings.Length == ccIndex + 3 || !ccPositions.isEmpty())) { // something like "soya or maize oil"
string leftHead = GetHeadTag(ccSiblings[ccIndex - 1]);
//create a new tree to be inserted as first child of t
Tree left = tf.NewTreeNode(lf.NewLabel(leftHead), null);
for (int i = 0; i < ccIndex + 2; i++)
{
left.AddChild(ccSiblings[i]);
}
// remove all the children of t before ccIndex+2
for (int i = 0; i < ccIndex + 2; i++)
{
t.RemoveChild(0);
}
// if stuff after (like "soya or maize oil and vegetables")
// we need to put the tree in another tree
if (ccPositions.Any())
{
bool comma = false;
int index = ccPositions[0];
if (ccSiblings[index - 1].Value() == PartsOfSpeech.Comma)
{
//to handle the case of a comma ("soya and maize oil, and vegetables")
index = index - 1;
comma = true;
}
string head = GetHeadTag(ccSiblings[index - 1]);
if (ccIndex + 2 < index)
{
Tree tree = tf.NewTreeNode(lf.NewLabel(head), null);
tree.AddChild(0, left);
int k = 1;
for (int j = ccIndex + 2; j < index; j++)
{
t.RemoveChild(0);
tree.AddChild(k, ccSiblings[j]);
k++;
}
t.AddChild(0, tree);
}
else
{
t.AddChild(0, left);
}
Tree rightTree = tf.NewTreeNode(lf.NewLabel(Noun), null);
int start = 2;
if (comma)
{
start++;
}
while (start < t.NumChildren())
{
Tree sib = t.GetChild(start);
t.RemoveChild(start);
rightTree.AddChild(sib);
}
t.AddChild(rightTree);
}
//.........这里部分代码省略.........
示例8: Main
static void Main()
{
var root = new Tree<string>("Grandfather");
var child11 = new Tree<string>("Father");
var child12 = new Tree<string>("Aunt");
var child211 = new Tree<string>("Sister");
var child212 = new Tree<string>("Brother");
var child221 = new Tree<string>("Cousin 1");
var child222 = new Tree<string>("Cousin 2");
root.AddChild(child11
.AddChild(child211)
.AddChild(child212)
)
.AddChild(child12
.AddChild(child221)
.AddChild(child222)
);
// var dfs = new DFSRecursive<string>(root);
// dfs.TraverseWithAction(root, Console.WriteLine);
// var dfsIterative = new DFSIterative<string>();
// Console.WriteLine("\n\nITERATIVE BELOW\n\n");
// dfsIterative.TraverseWithAction(root, x => Console.WriteLine(x));
// represent a graph using adjacency list
var graphRepresentaion = new Dictionary<IGraphNode<string>, IList<IGraphNode<string>>>()
{
// random links
{root, new List<IGraphNode<string>>(){child11, child12, child222}},
{child11, new List<IGraphNode<string>>(){root, child211}},
{child12, new List<IGraphNode<string>>(){child212, child211}},
{child212, new List<IGraphNode<string>>(){child11, root, child211}},
{child211, new List<IGraphNode<string>>(){root}}
};
// realize the links
foreach (var node in graphRepresentaion)
{
foreach (var neighbor in node.Value)
{
if(!node.Key.Children.Contains(neighbor))
{
node.Key.AddChild(neighbor);
}
}
}
// var visited = new List<IGraphNode<string>>();
// var nodes = new Queue<IGraphNode<string>>();
// new GraphBFS().TraverseWithAction(root, x => Console.WriteLine(x));
var gosho = new int[] { 1, 2, 3, 4, 5, 6, 7 }.Where(x => x % 2 == 0).Select(x => x + 3).ToArray();
var pesho = new int[,] { { 2, 3 }, { 3, 4 }, { -1, 17 } };
}
示例9: TestRecursion
public void TestRecursion()
{
StringTemplateGroup group = new StringTemplateGroup( "dummy", ".", typeof( AngleBracketTemplateLexer ) );
group.DefineTemplate( "tree",
"<if(it.firstChild)>" +
"( <it.text> <it.children:tree(); separator=\" \"> )" +
"<else>" +
"<it.text>" +
"<endif>" );
StringTemplate tree = group.GetInstanceOf( "tree" );
// build ( a b (c d) e )
Tree root = new Tree( "a" );
root.AddChild( new Tree( "b" ) );
Tree subtree = new Tree( "c" );
subtree.AddChild( new Tree( "d" ) );
root.AddChild( subtree );
root.AddChild( new Tree( "e" ) );
tree.SetAttribute( "it", root );
string expecting = "( a b ( c d ) e )";
Assert.AreEqual( expecting, tree.ToString() );
}
示例10: Update
private void Update(string _path, Tree<RemoteFileInfo> _tree)
{
try
{
RemoteDirectoryInfo directory = m_session.ListDirectory(_path);
foreach (WinSCP.RemoteFileInfo fileInfo in directory.Files)
{
if (fileInfo.Name != "..")
{
if (fileInfo.IsDirectory)
{
//if the entry not cached - add the directory and then update its contents
if (Tree<RemoteFileInfo>.Find(m_ignoreTree, i => i.Name == fileInfo.Name && i.IsDirectory) == null)
{
_tree.AddChild(new RemoteFileInfo(fileInfo));
Update(_path + "/" + fileInfo.Name, _tree.GetChild(_tree.Children.Count - 1));
}
}
else
{
//if we are not ignoring the file
if (Tree<RemoteFileInfo>.Find(m_ignoreTree, i => i.Name == fileInfo.Name && !i.IsDirectory) == null)
{
//if the file extension is one we care about add it to list, other wise add to the ignore list
//if (!m_ignoredExtensions.Contains(Utilities.GetExtensionFromFileName(fileInfo.Name)))
{
_tree.AddChild(new RemoteFileInfo(fileInfo));
}
//else
//{
// m_ignoreTree.AddChild(new RemoteFileInfo2(fileInfo));
//}
}
}
}
}
}
catch (Exception e)
{
LOG.ErrorFormat("Error: {0}", e);
}
}