コード例 #1
0
        protected Expression VisitBinary(BinaryExpression b)
        {
            int            num      = 0;
            ExpressionType nodeType = b.NodeType;

            switch (nodeType)
            {
            case ExpressionType.And:
            case ExpressionType.AndAlso:
            {
Label0:
                this.m_needsClosing.Push(true);
                break;
            }

            default:
            {
                switch (nodeType)
                {
                case ExpressionType.Or:
                case ExpressionType.OrElse:
                {
                    goto Label0;
                }

                default:
                {
                    this.m_needsClosing.Push(false);
                    break;
                }
                }
                break;
            }
            }
            if (!this.m_needsClosing.Peek() && !this.m_hasVisitiedBinary)
            {
                this.m_hasVisitiedBinary = true;
                if (b.Right.NodeType == ExpressionType.Constant && b.Right.Type == typeof(object))
                {
                    this.RecordCallerAndVisit(b.Left, null);
                    this.m_needsClosing.Pop();
                    return(b);
                }
            }
            bool flag   = false;
            bool flag1  = false;
            int  count  = -1;
            int  count1 = -1;

            this.PartialClause.Append("( ");
            this.isKeyAccess = false;
            bool methodCall = this.IsCompareToMethodCall(b.Left);

            if (!methodCall)
            {
                if (!this.m_needsClosing.Peek())
                {
                    ExpressionUtility.ValidateIsSimpleExpression(b.Left);
                    flag = ExpressionUtility.IsConstantExpressionEquivalent(b.Left);
                }
                this.RecordCallerAndVisit(b.Left, b);
                this.CloseBooleanExpression(b.NodeType, b.Left);
            }
            else
            {
                Expression item = ((MethodCallExpression)b.Left).Arguments[0];
                ExpressionUtility.ValidateIsSimpleExpression(item);
                flag = ExpressionUtility.IsConstantExpressionEquivalent(item);
                this.RecordCallerAndVisit(item, b.Left);
            }
            if (b.Left is ConstantExpression || b.Left.NodeType == ExpressionType.Convert)
            {
                num++;
            }
            if (flag)
            {
                count = this.Parameters.Count - 1;
            }
            this.ProcessBinaryExpressionOperator(b.NodeType);
            if (!methodCall)
            {
                this.RecordCallerAndVisit(b.Right, b);
                if (!this.m_needsClosing.Peek())
                {
                    flag1 = ExpressionUtility.IsConstantExpressionEquivalent(b.Right);
                }
                this.CloseBooleanExpression(b.NodeType, b.Right);
            }
            else
            {
                this.RecordCallerAndVisit(((MethodCallExpression)b.Left).Arguments[1], b.Left);
                if (!this.m_needsClosing.Peek())
                {
                    flag1 = ExpressionUtility.IsConstantExpressionEquivalent(((MethodCallExpression)b.Left).Arguments[1]);
                }
            }
            if (!this.m_needsClosing.Peek() && flag ^ flag1)
            {
                throw new NotImplementedException();
            }
            if (b.Right is ConstantExpression || b.Right.NodeType == ExpressionType.Convert)
            {
                num++;
            }
            if (flag1)
            {
                count1 = this.Parameters.Count - 1;
            }
            if (flag || flag1)
            {
                int num1 = -1;
                if (count != -1 && this.Parameters[count].IsStringValue)
                {
                    num1 = count;
                }
                else if (count1 != -1 && this.Parameters[count1].IsStringValue)
                {
                    num1 = count1;
                }
                if (num1 != -1)
                {
                    string value = this.Parameters[num1].Value as string;
                    if (value != null)
                    {
                        if (!this.isKeyAccess)
                        {
                            this.Parameters[num1].Value = DevelopmentStorageDbDataContext.EncodeDataString(value);
                        }
                        else
                        {
                            this.Parameters[num1].Value = DevelopmentStorageDbDataContext.EncodeKeyString(value);
                        }
                    }
                }
            }
            this.PartialClause.Append(")");
            this.m_needsClosing.Pop();
            if ((b.NodeType == ExpressionType.GreaterThan || b.NodeType == ExpressionType.GreaterThanOrEqual || b.NodeType == ExpressionType.LessThan || b.NodeType == ExpressionType.LessThanOrEqual || b.NodeType == ExpressionType.Equal || b.NodeType == ExpressionType.NotEqual) && num < 1)
            {
                CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                object[]    mLinqExpression  = new object[] { this.m_linqExpression };
                throw new NotSupportedException(string.Format(invariantCulture, "Query filter '{0}' not supported. A constant should be provided in a binary expression.", mLinqExpression));
            }
            return(b);
        }
コード例 #2
0
        protected override Expression VisitBinary(BinaryExpression b)
        {
            int num = 0;

            this.SqlQuery.Append("( ");
            ExpressionType nodeType = b.NodeType;

            switch (nodeType)
            {
            case ExpressionType.And:
            case ExpressionType.AndAlso:
            {
Label0:
                this.m_needsClosing.Push(true);
                break;
            }

            default:
            {
                switch (nodeType)
                {
                case ExpressionType.Or:
                case ExpressionType.OrElse:
                {
                    goto Label0;
                }

                default:
                {
                    this.m_needsClosing.Push(false);
                    break;
                }
                }
                break;
            }
            }
            bool methodCall = ExpressionUtility.IsCompareToMethodCall(b.Left);

            if (!methodCall)
            {
                if (!this.m_needsClosing.Peek())
                {
                    ExpressionUtility.ValidateIsSimpleExpression(b.Left);
                }
                this.Visit(b.Left);
            }
            else
            {
                Expression item = ((MethodCallExpression)b.Left).Arguments[0];
                ExpressionUtility.ValidateIsSimpleExpression(item);
                this.Visit(item);
            }
            if (b.Left is ConstantExpression || b.Left.NodeType == ExpressionType.Convert)
            {
                num++;
            }
            this.SqlQuery.AppendFormat(" {0} ", this.GetSqlQueryExpressionOperator(b.NodeType));
            if (!methodCall)
            {
                this.Visit(b.Right);
            }
            else
            {
                this.Visit(((MethodCallExpression)b.Left).Arguments[1]);
            }
            if (b.Right is ConstantExpression || b.Right.NodeType == ExpressionType.Convert)
            {
                num++;
            }
            this.SqlQuery.Append(")");
            this.m_needsClosing.Pop();
            if ((b.NodeType == ExpressionType.GreaterThan || b.NodeType == ExpressionType.GreaterThanOrEqual || b.NodeType == ExpressionType.LessThan || b.NodeType == ExpressionType.LessThanOrEqual || b.NodeType == ExpressionType.Equal || b.NodeType == ExpressionType.NotEqual) && num < 1)
            {
                CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                object[]    mLinqExpression  = new object[] { this.m_linqExpression };
                throw new NotSupportedException(string.Format(invariantCulture, "Query filter '{0}' not supported. A constant should be provided in a binary expression.", mLinqExpression));
            }
            return(b);
        }