TaskUtilsFind Method

Finds a task which satisfy the condition in a tree of tasks.

Namespace:  Aspose.Tasks.Util
Assembly:  Aspose.Tasks (in Aspose.Tasks.dll) Version: 20.11
public static Task Find(
	Task root,
	ICondition<Task> cond


Type: Aspose.TasksTask
Root of the tree.
Type: Aspose.Tasks.UtilIConditionTask
Applied condition.

Return Value

Type: Task
Task if task was found, otherwise null.
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