Exemplo n.º 1
0
        private BoundExpression BindCoalesceExpression(CoalesceExpressionSyntax node)
        {
            // COALESCE(e1, e2, .. eN)
            //
            // ====>
            //
            // CASE
            //   WHEN e1 IS NOT NULL THEN e1
            //   ..
            //   WHEN e2 IS NOT NULL THEN e2
            //   ELSE
            //     eN
            // END

            var boundArguments = BindToCommonType(node.ArgumentList.Arguments);
            var caseLabelCount = node.ArgumentList.Arguments.Count - 1;
            var caseLabels     = new BoundCaseLabel[caseLabelCount];

            for (var i = 0; i < caseLabelCount; i++)
            {
                var argument              = node.ArgumentList.Arguments[i];
                var boundArgument         = boundArguments[i];
                var boundIsNullExpression = new BoundIsNullExpression(boundArgument);
                var boundIsNullNegation   = BindUnaryExpression(argument.Span, UnaryOperatorKind.LogicalNot, boundIsNullExpression);
                var caseLabel             = new BoundCaseLabel(boundIsNullNegation, boundArgument);
                caseLabels[i] = caseLabel;
            }

            var elseExpresion = boundArguments.Last();

            return(new BoundCaseExpression(caseLabels, elseExpresion));
        }
Exemplo n.º 2
0
        private BoundExpression BindNullIfExpression(NullIfExpressionSyntax node)
        {
            // NULLIF(left, right)
            //
            // ===>
            //
            // CASE WHEN left != right THEN left END

            var expressions     = BindToCommonType(new[] { node.LeftExpression, node.RightExpression });
            var boundLeft       = expressions[0];
            var boundRight      = expressions[1];
            var boundComparison = BindBinaryExpression(node.Span, BinaryOperatorKind.NotEqual, boundLeft, boundRight);
            var boundCaseLabel  = new BoundCaseLabel(boundComparison, boundLeft);

            return(new BoundCaseExpression(new[] { boundCaseLabel }, null));
        }
 protected virtual BoundCaseLabel RewriteCaseLabel(BoundCaseLabel node)
 {
     return(node.Update(RewriteExpression(node.Condition),
                        RewriteExpression(node.ThenExpression)));
 }