internal static bool IsConstantExpressionEquivalent(Expression expression) { switch (expression.NodeType) { case ExpressionType.Constant: { return(true); } case ExpressionType.Convert: { return(ExpressionUtility.IsConstantExpressionEquivalent((expression as UnaryExpression).Operand)); } } return(false); }
protected Expression VisitMethodCall(MethodCallExpression m) { if (m.Method.DeclaringType == typeof(Queryable) && string.Equals(m.Method.Name, "Where")) { return(this.VisitWhere(m)); } if (!string.Equals(m.Method.Name, "GetValue")) { if (string.Equals(m.Method.Name, "Take")) { return(this.VisitTake(m)); } if (string.Equals(m.Method.Name, "OrderBy") || string.Equals(m.Method.Name, "ThenBy")) { return(this.VisitOrderBy(m)); } if (string.Equals(m.Method.Name, "AndAlso") && m.Arguments.Count == 2) { return(this.VisitAndOrCall(m, ExpressionType.AndAlso)); } if (string.Equals(m.Method.Name, "OrElse") && m.Arguments.Count == 2) { return(this.VisitAndOrCall(m, ExpressionType.OrElse)); } if (!string.Equals(m.Method.Name, "Select") || m.Arguments.Count != 2) { throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name)); } return(this.VisitSelectMethodCall(m)); } bool flag = true; bool flag1 = false; if (this.m_PreviousExpression != null) { ExpressionType nodeType = this.m_PreviousExpression.NodeType; switch (nodeType) { case ExpressionType.Equal: case ExpressionType.GreaterThan: case ExpressionType.GreaterThanOrEqual: case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: { if ((this.m_PreviousExpression as BinaryExpression).Right == m) { flag1 = true; if (!ExpressionUtility.IsConstantExpressionEquivalent((this.m_PreviousExpression as BinaryExpression).Left)) { throw new NotImplementedException(); } } flag = false; break; } case ExpressionType.ExclusiveOr: case ExpressionType.Invoke: case ExpressionType.Lambda: case ExpressionType.LeftShift: { break; } default: { if (nodeType != ExpressionType.NotEqual) { break; } else { goto case ExpressionType.LessThanOrEqual; } } } } this.ProcessMemberAccess(m); if (flag && this.HasOpenPropertyOnStack()) { this.InsertOpenTypeFilters(true, "1"); } else if (flag1 && this.HasOpenPropertyOnStack()) { this.InsertOpenTypeFiltersWhenRhs(this.Parameters[this.paramIndex - 1].Value); } return(m); }
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); }