TaskUtilsFilter Method

Builds new tree of tasks which satisfy the condition.

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


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

Return Value

Type: Task
Root of a new tree.
Shows how to work with a condition.
[Test] //ExSkip
public void WorkWithFilter()
    var project = new Project(DataDir + "Project2.mpp");

    // builds new tree of tasks which satisfy the condition 
    var task = TaskUtils.Filter(project.RootTask, new FilterByDuration(2));

    // 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 FilterByDuration : ICondition<Task>
    private readonly int days;

    public FilterByDuration(int days)
        this.days = days;

    /// <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.Duration).TimeSpan >= TimeSpan.FromHours(this.days * 8);
See Also