本文整理汇总了C#中ITask.FindTasks方法的典型用法代码示例。如果您正苦于以下问题:C# ITask.FindTasks方法的具体用法?C# ITask.FindTasks怎么用?C# ITask.FindTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITask
的用法示例。
在下文中一共展示了ITask.FindTasks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SolveReferences
/// <summary>
/// Solves all sub tree reference tasks and replaces them by real references to the sub tree.
/// </summary>
/// <param name="tree"> Tree in which to solve references. </param>
/// <returns> Task to use instead of the passed one. </returns>
private ITask SolveReferences(ITask tree)
{
if (tree == null)
{
return tree;
}
// Check if root is reference.
if (tree is SubTreeReference)
{
SubTreeReference subTreeReference = tree as SubTreeReference;
// Resolve reference.
ITask treeReference = this.SolveReference(subTreeReference);
return treeReference;
}
// Find sub tree reference tasks in tree.
ICollection<TaskNode> referenceNodes = new List<TaskNode>();
TaskNode rootNode = new TaskNode { Task = tree };
tree.FindTasks(rootNode, task => task is SubTreeReference, ref referenceNodes);
// Replace tasks in found nodes by referenced tree.
foreach (TaskNode referenceNode in referenceNodes)
{
SubTreeReference subTreeReference = referenceNode.Task as SubTreeReference;
if (subTreeReference == null)
{
throw new Exception(
"Searched for SubTreeReference nodes, but found a task which is no sub tree reference node.");
}
IComposite parentComposite = referenceNode.ParentTask as IComposite;
if (parentComposite == null)
{
throw new Exception("Found task which has no parent composite.");
}
// Resolve reference.
ITask treeReference = this.SolveReference(subTreeReference);
// Remove from parent.
parentComposite.RemoveChild(referenceNode.Task);
// Add tree reference to parent at same position.
parentComposite.InsertChild(referenceNode.Index, treeReference);
}
return tree;
}