private void ValidateCandidates(Expression expression, List <Expression> candidates)
        {
            List <Expression> toRemove = new List <Expression>();

            foreach (var candidate in candidates)
            {
                if (toRemove.Contains(candidate))
                {
                    continue;
                }

                if (typeof(IEnumerable).IsAssignableFrom(candidate.Type) && candidate.NodeType == ExpressionType.New)
                {
                    var parents = ExpressionSearcher.GetParents(candidate, expression);

                    var listInit = parents.Where(p => p.NodeType == ExpressionType.ListInit).ToList();

                    if (!CanEvaluateLocally(listInit))
                    {
                        toRemove.Add(candidate);

                        foreach (var c in candidates)
                        {
                            if (parents.Any(p => p == c))
                            {
                                toRemove.AddRange(parents.Where(p => p == c));
                            }
                        }
                    }
                }
            }

            if (toRemove.Count > 0)
            {
                Logger.Log($"Removing {toRemove.Count} incorrectly flagged candidates", Indentation.Two, toRemove);

                foreach (var expr in toRemove)
                {
                    candidates.Remove(expr);
                }
            }
        }
        private bool IsLegalFilterInternal(Expression filter)
        {
            Logger.Log($"Determining whether expression '{filter}' is a legal filter", Indentation.Five);

            var properties = ExpressionSearcher.Search(filter, e => e is PropertyExpression).Cast <PropertyExpression>().ToList();

            if (!HasSinglePropertyExpression(filter, properties))
            {
                return(false);
            }

            if (!HasExtraMemberExpressions(filter))
            {
                return(false);
            }

            if (!HasOnlyLegalExpressionTypes(filter))
            {
                return(false);
            }

            var property = properties.Single();
            var parents  = ExpressionSearcher.GetParents(property, filter).ToList();

            if (!HasOnlyLegalCasts(property, parents))
            {
                return(false);
            }

            if (!HasOnlyLegalParents(filter, parents))
            {
                return(false);
            }

            Logger.Log("Filter did not match any exclusion criteria. Including filter", Indentation.Six);
            return(true);
        }