ClearCanvas.Desktop.View.WinForms.BindingTreeView.FindNodeRecursive C# (CSharp) Method

FindNodeRecursive() private method

Searches the tree depth-first for a node matching the specified criteria
private FindNodeRecursive ( TreeNodeCollection nodeCollection, Predicate criteria ) : ClearCanvas.Desktop.View.WinForms.BindingTreeNode
nodeCollection System.Windows.Forms.TreeNodeCollection
criteria Predicate
return ClearCanvas.Desktop.View.WinForms.BindingTreeNode
        private BindingTreeNode FindNodeRecursive(TreeNodeCollection nodeCollection, Predicate<BindingTreeNode> criteria)
        {
            foreach (TreeNode node in nodeCollection)
            {
                //  Bug #871
                //  See BindingTreeNode.UpdateDisplay():  
                //  the Nodes property may contain a "dummy" TreeNode, so ensure each iterated TreeNode is actually a BindingTreeNode
                BindingTreeNode bindingTreeNode = node as BindingTreeNode;

                if (bindingTreeNode != null && criteria(bindingTreeNode))
                {
                    return bindingTreeNode;
                }
                else
                {
                    BindingTreeNode nodeFound = FindNodeRecursive(node.Nodes, criteria);
                    if (nodeFound != null)
                        return nodeFound;
                }
            }
            return null;
        }