private Expression Filter(Expression visited, Expression processed)
            {
                if (this.filter == null)
                {
                    this.filter = this.context.QueryContext.GetHookHandler <IQueryExpressionFilter>();
                }

                if (this.filter != null)
                {
                    var filtered = filter.Filter(this.context);
                    var callback = this.context.AfterNestedVisitCallback;
                    this.context.AfterNestedVisitCallback = null;
                    if (filtered != null && filtered != visited)
                    {
                        if (!visited.Type.IsAssignableFrom(filtered.Type))
                        {
                            throw new InvalidOperationException(
                                      Resources.FilterCannotChangeExpressionType);
                        }

                        this.processedExpressions.Add(visited, processed);
                        this.context.PushVisitedNode(null);
                        try
                        {
                            processed = this.Visit(filtered);
                        }
                        finally
                        {
                            this.context.PopVisitedNode();
                            this.processedExpressions.Remove(visited);
                        }

                        if (callback != null)
                        {
                            callback();
                        }
                    }
                }

                return(processed);
            }
            private Expression Filter(Expression visited, Expression processed)
            {
                if (this.filter == null)
                {
                    this.filter = this.context.QueryContext.GetHookHandler<IQueryExpressionFilter>();
                }

                if (this.filter != null)
                {
                    var filtered = filter.Filter(this.context);
                    var callback = this.context.AfterNestedVisitCallback;
                    this.context.AfterNestedVisitCallback = null;
                    if (filtered != null && filtered != visited)
                    {
                        if (!visited.Type.IsAssignableFrom(filtered.Type))
                        {
                            throw new InvalidOperationException(
                                Resources.FilterCannotChangeExpressionType);
                        }

                        this.processedExpressions.Add(visited, processed);
                        this.context.PushVisitedNode(null);
                        try
                        {
                            processed = this.Visit(filtered);
                        }
                        finally
                        {
                            this.context.PopVisitedNode();
                            this.processedExpressions.Remove(visited);
                        }

                        if (callback != null)
                        {
                            callback();
                        }
                    }
                }

                return processed;
            }