TaskUtils.Find
Contents
[
Hide
]TaskUtils.Find method
Finds a task which satisfy the condition in a tree of tasks.
public static Task Find(Task root, ICondition<Task> cond)
Parameter | Type | Description |
---|---|---|
root | Task | Root of the tree. |
cond | ICondition`1 | Applied condition. |
Return Value
Task if task was found, otherwise null.
Examples
Shows how to use <see cref=“Aspose.Tasks.Util.TaskUtils.Find” /> method.
public void WorkWithFind()
{
var project = new Project(DataDir + "Project2.mpp");
// builds new tree of tasks which satisfy the condition
var task = TaskUtils.Filter(project.RootTask, new FindByName("Task8"));
// gather tasks from a tree
var coll = new ChildTasksCollector();
TaskUtils.Apply(task, coll, 0);
// iterate over plain list of tasks
// which durations are greater or equal than 2 working days
foreach (var collTask in coll.Tasks)
{
Console.WriteLine("Name: " + collTask.Get(Tsk.Name) + "Duration: " + collTask.Get(Tsk.Duration).TimeSpan);
}
}
private class FindByName : ICondition<Task>
{
private readonly string name;
public FindByName(string name)
{
this.name = name;
}
/// <summary>
/// Returns true if the specified object satisfy the conditions.
/// </summary>
/// <param name="el">The object to check.</param>
/// <returns>True if the object satisfy the conditions.</returns>
/// <inheritdoc />
public bool Check(Task el)
{
return el.Get(Tsk.Name) == this.name;
}
}
See Also
- class Task
- interface ICondition<T>
- class TaskUtils
- namespace Aspose.Tasks.Util
- assembly Aspose.Tasks