public static void EnumNodes(Expression root, EnumNodesCallBack callback, EnumNodesCallBack postCallback, params object[] args) { switch( root.NodeType ) { case NodeType.Literal: case NodeType.Parameter: case NodeType.Context: { if( callback != null ) { callback(root, args); } if( postCallback != null ) { postCallback(root, args); } return; } case NodeType.Binary: { if( callback == null || callback(root, args) ) { Binary node = (Binary)root; Expression.EnumNodes(node.Left, callback, postCallback, args); Expression.EnumNodes(node.Right, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.Unary: { if( callback == null || callback(root, args) ) { Unary node = (Unary)root; Expression.EnumNodes(node.Operand, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.Axis: case NodeType.Filter: { if( callback == null || callback(root, args) ) { Filter node = (Filter)root; Expression.EnumNodes(node.Source, callback, postCallback, args); Expression.EnumNodes(node.Constraint, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.Property: { if( callback == null || callback(root, args) ) { Property node = (Property)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.Parent: { if( callback == null || callback(root, args) ) { Parent node = (Parent)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.Function: { if( callback == null || callback(root, args) ) { Function node = (Function)root; for( int i = 0; i < node.Params.Length; i++ ) { Expression.EnumNodes(node.Params[i], callback, postCallback, args); } if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.TypeFilter: { if( callback == null || callback(root, args) ) { TypeFilter node = (TypeFilter)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } case NodeType.Empty: { return; } case NodeType.OrderBy: { if( callback == null || callback(root, args) ) { OrderBy node = (OrderBy)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if( postCallback != null ) { postCallback(root, args); } } return; } default: { throw new NotSupportedException("Expression type '" + root.GetType() + "' is not currently supported."); } } }
public static void EnumNodes(Expression root, EnumNodesCallBack callback, EnumNodesCallBack postCallback, params object[] args) { switch (root.NodeType) { case NodeType.Literal: case NodeType.Parameter: case NodeType.Context: { if (callback != null) { callback(root, args); } if (postCallback != null) { postCallback(root, args); } return; } case NodeType.Binary: { if (callback == null || callback(root, args)) { Binary node = (Binary)root; Expression.EnumNodes(node.Left, callback, postCallback, args); Expression.EnumNodes(node.Right, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.Unary: { if (callback == null || callback(root, args)) { Unary node = (Unary)root; Expression.EnumNodes(node.Operand, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.Axis: case NodeType.Filter: { if (callback == null || callback(root, args)) { Filter node = (Filter)root; Expression.EnumNodes(node.Source, callback, postCallback, args); Expression.EnumNodes(node.Constraint, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.Property: { if (callback == null || callback(root, args)) { Property node = (Property)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.Parent: { if (callback == null || callback(root, args)) { Parent node = (Parent)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.Function: { if (callback == null || callback(root, args)) { Function node = (Function)root; for (int i = 0; i < node.Params.Length; i++) { Expression.EnumNodes(node.Params[i], callback, postCallback, args); } if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.TypeFilter: { if (callback == null || callback(root, args)) { TypeFilter node = (TypeFilter)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } case NodeType.Empty: { return; } case NodeType.OrderBy: { if (callback == null || callback(root, args)) { OrderBy node = (OrderBy)root; Expression.EnumNodes(node.Source, callback, postCallback, args); if (postCallback != null) { postCallback(root, args); } } return; } default: { throw new NotSupportedException("Expression type '" + root.GetType() + "' is not currently supported."); } } }
public static void EnumNodes(Expression root, EnumNodesCallBack callback) { EnumNodes(root, callback, null, null); }