src/Shared/EntityFramework.SqlServer/Utilities/DbExpressionExtensions.cs
// <summary>
// Uses a stack to non-recursively traverse a given tree structure and retrieve the leaf nodes.
// </summary>
// <param name="root"> The node that represents the root of the tree. </param>
// <param name="kind"> Expressions not of this kind are considered leaves. </param>
// <param name="getChildNodes">
// A function that traverses the tree by retrieving the <b>immediate</b> descendants of a (non-leaf) node.
// </param>
// <returns> An enumerable containing the leaf nodes. </returns>
Uses a stack to non-recursively traverse a given tree structure and retrieve the leaf nodes.
Uses a stack to non - recursively traverse a given tree structure and retrieve the leaf nodes .
public static IEnumerable<DbExpression> GetLeafNodes(
            this DbExpression root,
            DbExpressionKind kind,
            Func<DbExpression, IEnumerable<DbExpression>> getChildNodes)
        {
            DebugCheck.NotNull(getChildNodes);
            var nodes = new Stack<DbExpression>();
            nodes.Push(root);
            while (nodes.Count > 0)
            {
                var current = nodes.Pop();
                if (current.ExpressionKind != kind)
                {
                    yield return current;
                }
                else
                {
                    foreach (var node in getChildNodes(current).Reverse())
                    {
                        nodes.Push(node);
                    }
                }
            }
        }
public static IEnumerable < DbExpression > GetLeafNodes ( this DbExpression root , DbExpressionKind kind , Func < DbExpression , IEnumerable < DbExpression > > getChildNodes ) { DebugCheck . NotNull ( getChildNodes ) ; var nodes = new Stack < DbExpression > ( ) ; nodes . Push ( root ) ; while ( nodes . Count > 0 ) { var current = nodes . Pop ( ) ; if ( current . ExpressionKind != kind ) { yield return current ; } else { foreach ( var node in getChildNodes ( current ) . Reverse ( ) ) { nodes . Push ( node ) ; } } } }
Uses a stack to non-recursively traverse a given tree structure and retrieve the leaf nodes.
Uses a stack to non - recursively traverse a given tree structure and retrieve the leaf nodes .
An enumerable containing the leaf nodes.
An enumerable containing the leaf nodes .
DbExpression
this
kind
DbExpressionKind
Expressions not of this kind are considered leaves.
Expressions not of this kind are considered leaves .
getChildNodes
Func<DbExpression, IEnumerable<DbExpression>>
A function that traverses the tree by retrieving the immediate
A function that traverses the tree by retrieving the immediate
root
The node that represents the root of the tree.
The node that represents the root of the tree .