Beispiel #1
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                c.Expression = this.VisitExpression(c.Expression);
                int num   = 0;
                int num2  = 0;
                int count = c.Whens.Count;

                while (num2 < count)
                {
                    if (c.Whens[num2].Match == null)
                    {
                        num = num2;
                        break;
                    }
                    num2++;
                }
                c.Whens[num].Match = this.VisitExpression(c.Whens[num].Match);
                c.Whens[num].Value = this.VisitExpression(c.Whens[num].Value);
                List <SqlWhen> newWhens         = new List <SqlWhen>();
                bool           allValuesLiteral = true;
                int            num4             = 0;
                int            num5             = c.Whens.Count;

                while (num4 < num5)
                {
                    if (num != num4)
                    {
                        SqlWhen item = c.Whens[num4];
                        item.Match = this.VisitExpression(item.Match);
                        item.Value = this.VisitExpression(item.Value);
                        if (!SqlComparer.AreEqual(c.Whens[num].Value, item.Value))
                        {
                            newWhens.Add(item);
                        }
                        allValuesLiteral = allValuesLiteral && (item.Value.NodeType == SqlNodeType.Value);
                    }
                    num4++;
                }
                newWhens.Add(c.Whens[num]);
                SqlExpression expression = this.TryToConsolidateAllValueExpressions(newWhens.Count, c.Whens[num].Value);

                if (expression != null)
                {
                    return(expression);
                }
                expression = this.TryToWriteAsSimpleBooleanExpression(c.ClrType, c.Expression, newWhens, allValuesLiteral);
                if (expression != null)
                {
                    return(expression);
                }
                expression = this.TryToWriteAsReducedCase(c.ClrType, c.Expression, newWhens, c.Whens[num].Match, c.Whens.Count);
                if (expression != null)
                {
                    return(expression);
                }
                return(c);
            }
Beispiel #2
0
        private SqlExpression ConvertBitToString(SqlExpression expr, Type resultClrType)
        {
            var        whens = new SqlWhen[1];
            const bool flag  = true;

            whens[0] = new SqlWhen(expr, sql.ValueFromObject(flag.ToString(), false, expr.SourceExpression));
            const bool flag2 = false;

            return(new SqlSearchedCase(resultClrType, whens, sql.ValueFromObject(flag2.ToString(), false, expr.SourceExpression), expr.SourceExpression));
        }
Beispiel #3
0
        internal virtual SqlExpression VisitSearchedCase(SqlSearchedCase c)
        {
            int num   = 0;
            int count = c.Whens.Count;

            while (num < count)
            {
                SqlWhen when = c.Whens[num];
                when.Match = this.VisitExpression(when.Match);
                when.Value = this.VisitExpression(when.Value);
                num++;
            }
            c.Else = this.VisitExpression(c.Else);
            return(c);
        }
Beispiel #4
0
        internal virtual SqlExpression VisitSimpleCase(SqlSimpleCase c)
        {
            c.Expression = this.VisitExpression(c.Expression);
            int num   = 0;
            int count = c.Whens.Count;

            while (num < count)
            {
                SqlWhen when = c.Whens[num];
                when.Match = this.VisitExpression(when.Match);
                when.Value = this.VisitExpression(when.Value);
                num++;
            }
            return(c);
        }
Beispiel #5
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                SqlExpression expr = this.VisitExpression(c.Expression);

                SqlWhen[] whens  = new SqlWhen[c.Whens.Count];
                int       index  = 0;
                int       length = whens.Length;

                while (index < length)
                {
                    SqlWhen when = c.Whens[index];
                    whens[index] = new SqlWhen(this.VisitExpression(when.Match), this.VisitExpression(when.Value));
                    index++;
                }
                return(new SqlSimpleCase(c.ClrType, expr, whens, c.SourceExpression));
            }