コード例 #1
0
        /// <exception cref="OverflowException"><paramref name="condition.Operand" /> Enum Names should be equivalent</exception>
        private Expression BuildExpressionForCondition(Condition condition, Expression paramUser, int level = 0)
        {
            var leftLocatorExpression = BuildLocatorExpression(condition.Left, paramUser, ++level);

            if (condition.Right != null && condition.Right.IsLambda)
            {
                return(BuildLocatorExpression(condition.Right, leftLocatorExpression, ++level));
            }

            if (condition.Right == null)
            {
                return(leftLocatorExpression);
            }
            var rightLocatorExpression = BuildLocatorExpression(condition.Right, paramUser, ++level);

            var expressionType = ExpressionTypeHelper.GetByConditionOperand(condition.Operand);
            var result         = Expression.MakeBinary(expressionType, leftLocatorExpression,
                                                       Expression.Convert(rightLocatorExpression, leftLocatorExpression.Type));

            return(result);
        }
コード例 #2
0
        /// <exception cref="OverflowException"><paramref name="conditions" /> Enum Names should be equivalent</exception>
        public Expression BuildExpressionForConditions(ICollection <Condition> conditions, ParameterExpression parameter,
                                                       int level)
        {
            Expression result = Expression.Constant(true);

            if (conditions.Any())
            {
                result = BuildExpressionForCondition(conditions.First(), parameter, ++level);
                if (conditions.Count == 1)
                {
                    return(result);
                }
            }

            foreach (var condition in conditions.Skip(1))
            {
                var binaryOperation     = ExpressionTypeHelper.GetByAggregator(condition.Aggregator);
                var conditionExpression = BuildExpressionForCondition(condition, parameter, ++level);
                result = Expression.MakeBinary(binaryOperation, result, Expression.Convert(conditionExpression, result.Type));
            }
            return(result);
        }