/// <summary> /// Creates an enumerable traversing the tree starting with the given node. /// </summary> /// <typeparam name="TNode">The node base type used in the current tree. Inferred by the instance this method is called upon.</typeparam> /// <param name="root">The root node where to start the traversal.</param> /// <param name="match">The matching predicate. Enumeration will yield on every matching node.</param> /// <returns>An enumerable that can be used in foreach statements.</returns> public static IEnumerable <TNode> FindNodes <TNode>(this TNode root, Predicate <TNode> match) where TNode : class, INode { return(new SceneNodeEnumerable <TNode, TNode, IComponent> { _match = match, _rootList = VisitorHelpers.SingleRootEnumerator(root) }); }
/// <summary>Finds all nodes containing one or more components matching a given search predicate within a tree of nodes.</summary> /// <typeparam name="TComponentToFind">The type of the components to find.</typeparam> /// <typeparam name="TNode">The type of nodes making up the tree.</typeparam> /// <typeparam name="TComponent">The base type of components used in the given hierarchy.</typeparam> /// <param name="root">The root node where to start the search.</param> /// <param name="match">The search predicate. Typically specified as a Lambda expression.</param> /// <returns>All nodes containing matching components.</returns> public static IEnumerable <TNode> FindNodesWhereComponent <TComponentToFind, TNode, TComponent>(this TNode root, Predicate <TComponentToFind> match) where TComponentToFind : class, TComponent where TNode : class, INode where TComponent : class, IComponent { return(new SceneNodeWhereComponentEnumerable <TComponentToFind, TNode, TComponent> { _match = match, _rootList = VisitorHelpers.SingleRootEnumerator(root) }); }
/// <summary>Performs a <see cref="Viserator{TItem,TState,TNode,TComponent}"/> action on the specified tree.</summary> /// <typeparam name="TViserator">The type of the viserator.</typeparam> /// <typeparam name="TResult">The type of the elements resulting from the Viserate traversal.</typeparam> /// <typeparam name="TNode">The root type of nodes the tree (given by root) is built from.</typeparam> /// <typeparam name="TComponent">The root type of components used in the given tree.</typeparam> /// <param name="root">The root where to start the traversal.</param> /// <returns>All items yielded from within the traversal (<see cref="ViseratorBase{TItem,TNode,TComponent}.YieldItem"/>).</returns> public static IEnumerable <TResult> Viserate <TViserator, TResult, TNode, TComponent>(this TNode root) where TViserator : ViseratorBase <TResult, TNode, TComponent>, new() where TNode : class, INode where TComponent : class, IComponent { return(new ViseratorEnumerable <TViserator, TResult, TNode, TComponent> { _rootList = VisitorHelpers.SingleRootEnumerable(root) }); }