Example #1
0
        public static Expression Optimise(Expression expression)
        {
            if (expression == False)
            {
                return(expression);
            }

            var optimiser = new FilterOptimiser();

            do
            {
                optimiser._incomplete = false;
                expression            = optimiser.VisitAndConvert(expression, nameof(FilterOptimiser));
            }while (optimiser._incomplete);

            return(expression);
        }
        public Expression GetConditionOrNull(Expression sourceValue, IMemberMapperData mapperData)
        {
            var hasFixedValueOperands = false;
            var filterExpression      = GetFilterExpression(sourceValue, ref hasFixedValueOperands);

            if (hasFixedValueOperands)
            {
                filterExpression = FilterOptimiser.Optimise(filterExpression);
            }

            if (filterExpression == False)
            {
                return(null);
            }

            var condition = GetConditionOrNull(mapperData);

            if (condition != null)
            {
                filterExpression = Expression.AndAlso(condition, filterExpression);
            }

            return(filterExpression.Negate());
        }