Пример #1
0
        /// <exception cref="OverflowException"><paramref name="locator.Conditions" /> Enum Names should be equivalent</exception>
        public override Expression BuildExpression(Locator locator, Expression parent, int level)
        {
            var result = parent; //ExpressionHelper.MakeAsEnumerableExpression(parent);

            if (locator.Conditions != null && locator.Conditions.Any())
            {
                var        type       = result.Type.GenericTypeArguments.First();
                var        parameter  = Expression.Parameter(type, $"{type.Name.ToLower()}{level}");
                var        lambdaBody = _factory.BuildExpressionForConditions(locator.Conditions, parameter, level);
                Expression lambda     = Expression.Lambda(lambdaBody, parameter);
                result = MakeAnyExpression(lambda, result);
                return(result);
            }
            if (locator.Conditions != null && locator.Left != null && !locator.Conditions.Any())
            {
                var type       = result.Type.GenericTypeArguments.First();
                var parameter  = Expression.Parameter(type, $"{type.Name.ToLower()}{level}");
                var lambdaBody = _factory.BuildLocatorExpression(locator.Left, parameter, level);
                if (locator.Left.Type == LocatorType.Constant)
                {
                    lambdaBody = Expression.Equal(parameter, lambdaBody);
                }
                Expression lambda = Expression.Lambda(lambdaBody, parameter);
                result = MakeAnyExpression(lambda, result);
                return(result);
            }
            result = MakeAnyExpression(result);
            return(result);
        }
Пример #2
0
        /// <exception cref="OverflowException">Enum Names should be equivalent</exception>
        /// <exception cref="InvalidOperationException">!predicateLocator.Conditions.Any().</exception>
        public override Expression BuildExpression(Locator locator, Expression parent, int level)
        {
            var predicateLocator = (PredicateLocator)locator;

            if (predicateLocator.Conditions.Any())
            {
                var type       = parent.Type;
                var parameter  = Expression.Parameter(type, $"{type.Name.ToLower()}{level}");
                var lambdaBody = _factory.BuildExpressionForConditions(predicateLocator.Conditions, parameter,
                                                                       level);
                Expression lambda = Expression.Lambda(lambdaBody, parameter);
                parent = MakePredicateExpression(lambda, parent);
                return(parent);
            }
            throw new InvalidOperationException();
        }