/// <summary> /// Passes each child of this node to the <paramref name="nodeProcessor"/> provided recursively down the /// tree. It does not include this node. /// </summary> /// <param name="nodeProcessor">The object that will process each node down the tree.</param> /// <returns>True if every execution of the <see cref="ITreeNodeProcessor{TId, T}.ProcessNode(ITreeNode{TId, T})"/> method returns true, false if at least one of the executions returns false.</returns> public bool ProcessChildren(ITreeNodeProcessor <TId, T> nodeProcessor) { bool flag = true; foreach (ITreeNode <TId, T> local in Children) { flag = (flag & nodeProcessor.ProcessNode(local)) & local.ProcessChildren(nodeProcessor); } return(flag); }
/// <summary> /// Executes the <paramref name="nodeProcessor"/> starting with the <paramref name="treeNode"/> object /// and then recursively up the ancestor tree until the root or the node defined by <paramref name="maxLevel"/> /// </summary> /// <param name="nodeProcessor">The <see cref="ITreeNodeProcessor{TId, T}"/> object used to process the nodes up the ancestor tree</param> /// <param name="treeNode">The <see cref="ITreeNode{TId, T}"/> object used as the starting point for processing up the ancestor tree</param> /// <param name="maxLevel">(Optional) If defined will be used to check the <see cref="DepthFromRoot"/> property and will stop when it gets to that level</param> /// <returns></returns> public bool ProcessAncestors(ITreeNodeProcessor <TId, T> nodeProcessor, ITreeNode <TId, T> treeNode, int maxLevel = MIN_DEPTH_VALUE) { bool flag = true; flag = flag & nodeProcessor.ProcessNode(treeNode) & // Process this node treeNode.Parent == null || // There is no parent so evaluate to true treeNode.DepthFromRoot == maxLevel || // Instructed to stop here so evalutate to true ProcessAncestors(nodeProcessor, treeNode.Parent, maxLevel); // Go up the tree and return the result return(flag); }
/// <summary> /// Passes each child of this node to the <paramref name="nodeProcessor"/> provided recursively down the /// tree. Unlike <see cref="ProcessChildren(ITreeNodeProcessor{TId, T})"/>, this method will start with (include) this node. /// </summary> /// <param name="nodeProcessor">The object that will process each node down the tree.</param> /// <returns>True if every execution of the <see cref="ITreeNodeProcessor{TId, T}.ProcessNode(ITreeNode{TId, T})"/> method returns true, false if at least one of the executions returns false.</returns> public bool ProcessTree(ITreeNodeProcessor <TId, T> nodeProcessor) { return(nodeProcessor.ProcessNode(this) & ProcessChildren(nodeProcessor)); }