예제 #1
0
        private Clause CreateClauseFromExpression(BinaryExpression binaryExp)
        {
            if (binaryExp.NodeType == ExpressionType.AndAlso || binaryExp.NodeType == ExpressionType.OrElse)
            {
                BinaryExpression leftExpression = binaryExp.Left as BinaryExpression;
                if (leftExpression == null)
                {
                    throw new UnsupportedExpressionException("Expression in left side is invalid.", nameof(BinaryExpression));
                }
                BinaryExpression rightsExpression = binaryExp.Right as BinaryExpression;
                if (rightsExpression == null)
                {
                    throw new UnsupportedExpressionException("Expression in right side is invalid.", nameof(BinaryExpression));
                }

                return(new LogicalClause(
                           SqlBuilderHelper.MapExpressionTypeToBooleanOperation(binaryExp.NodeType),
                           CreateClauseFromExpression(leftExpression),
                           CreateClauseFromExpression(rightsExpression)
                           ));
            }

            return(new ComparisonClause(
                       SqlBuilderHelper.MapExpressionTypeToBinaryOperation(binaryExp.NodeType),
                       SqlBuilderHelper.GetClassNameFromExpression(binaryExp.Left),
                       SqlBuilderHelper.GetMemberNameFromExpression(binaryExp.Left),
                       SqlBuilderHelper.GetRightValueFromBinaryExpression(binaryExp)
                       ));
        }