Recursive Helper | Xafari Framework

Recursive Helper

The Recursive Helper class implements the main operations for the recursive processing of the hierarchical data. Each developer uses the recursive algorithms from time to time. The most typical case of this is tree-like (hierarchical) data processing.

To implement a recursive algorithm the developer needs to implement at least one or several auxiliary methods.

The figure below shows an example of a standard implementation of a traversal recursive algorithm.

public class Class1
{
public int Int1 { get; set; }
public List Children { get; set; }
}

void GoRound(Class1 obj)
{
Console.WriteLine(obj.Int1);
if (obj.Children != null)
foreach (var class1 in obj.Children)
GoRound(class1);
}

GoRound(data);

The same task can be solved using Recursive Helper as in the figure below.

RecursiveHelper.Recursive(data, a => a.Children, a => Console.WriteLine(a.Int1));

An alternative version:

data.Recursive(a => a.Children, a => Console.WriteLine(a.Int1));

Recursive Helper implements the following methods:

  • Recursive data processing
  • Obtaining of a linear list of objects hierarchy
  • Item search by path
  • Item search by condition
  • Processing of the data, supporting ITree Node.