i have this two method
public static void NavigateAndExecute(Node root, Action<Node> actionToExecute)
{
if (root == null || root.Children == null || root.Children.Count == 0)
return;
actionToExecute(root);
foreach (var node in root.Children)
{
actionToExecute(node);
NavigateAndExecute(node, actionToExecute);
}
}
public static void NavigateAndExecute(List<Node> root, Action<Node> actionToExecute)
{
if (root == null || root.Count == 0)
return;
foreach (var node in root)
{
NavigateAndExecute(node, actionToExecute);
}
}
Node class is
public class Node
{
public String Name { get; set; }
public List<Node> Children { get; set; }
}
this two methods worked on just the Node class, can make them work on any type T
any help.
You want a Generic Tree Collection. I wrote one years ago which I’ve open-sourced:
http://simplygenius.net/Article/TreeCollection2
I know the arguments against using Tree data structures, but sometimes they’re just what you need.