/// <summary> /// Searches active tool from top level, depth first, given predicate. /// </summary> /// <typeparam name="T">Type of the tool.</typeparam> /// <param name="tool">Parent tool to start from.</param> /// <param name="pred">Tool predicate.</param> /// <returns>Tool given type and predicate if active - otherwise null.</returns> public static T FindActive <T>(Tool tool, Predicate <T> pred) where T : Tool { if (tool == null) { return(null); } T typedTool = tool as T; if (typedTool != null && pred(typedTool)) { return(typedTool); } foreach (Tool child in tool.GetChildren()) { T result = FindActive(child, pred); if (result != null) { return(result); } } return(null); }
private static void TraverseActive(Tool parent, Action <Tool> visitor) { if (parent == null || visitor == null) { return; } visitor(parent); foreach (var child in parent.GetChildren()) { TraverseActive(child, visitor); } }