public static bool CheckIfStringCompareTo(BinaryExpression binaryExpression, bool isNot, out Expressions.BooleanComparisonExpression stringComparison) { stringComparison = null; //check that it follows: o.prop.CompareTo("text") > < >= <= != == 0 1 -1 if (binaryExpression.Left.NodeType == ExpressionType.Call && binaryExpression.Left is MethodCallExpression methodCallExpression && methodCallExpression.Method.Name == "CompareTo" && methodCallExpression.Object is MemberExpression memberExpression && methodCallExpression.Object.Type.Equals(typeof(string)) && binaryExpression.Right.NodeType == ExpressionType.Constant && binaryExpression.Right is ConstantExpression constantExpression && methodCallExpression.Arguments.Count == 1 && methodCallExpression.Arguments[0] is ConstantExpression argumentExpression) { Expressions.BooleanComparisonType booleanComparisonType = FilterUtils.ParseBooleanComparisonType(binaryExpression.NodeType); var compareValue = (long)Convert.ChangeType(constantExpression.Value, typeof(long)); var convertedComparison = ConvertNot(ConvertBooleanComparisonType(booleanComparisonType, compareValue), isNot); var columnReference = new Expressions.ColumnReference() { Identifiers = new List <string>() { memberExpression.Member.Name } }; stringComparison = new Expressions.BooleanComparisonExpression() { Left = columnReference, Right = new StringLiteral() { Value = (string)argumentExpression.Value }, Type = convertedComparison }; return(true); } return(false); }
private void VisitBooleanComparisonExpression(BinaryExpression binaryExpression) { //Check if it is a string compareTo if (FilterUtils.CheckIfStringCompareTo(binaryExpression, _inNot, out var stringComparison)) { _stack.Push(stringComparison); return; } var left = VisitPop <Expressions.ScalarExpression>(binaryExpression.Left); var right = VisitPop <Expressions.ScalarExpression>(binaryExpression.Right); Expressions.BooleanComparisonType booleanComparisonType = FilterUtils.ConvertNot(FilterUtils.ParseBooleanComparisonType(binaryExpression.NodeType), _inNot); _stack.Push(new Expressions.BooleanComparisonExpression() { Type = booleanComparisonType, Left = left, Right = right }); }