Ejemplo n.º 1
0
        protected override Expression VisitParameter(ParameterExpression node)
        {
            var columnReference = new Expressions.ColumnReference()
            {
                Identifiers = new List <string>()
                {
                    node.Name
                }
            };

            _stack.Push(columnReference);
            return(base.VisitParameter(node));
        }
Ejemplo n.º 2
0
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.Expression != null && node.Expression.NodeType == ExpressionType.Parameter)
            {
                var columnReference = new Expressions.ColumnReference()
                {
                    Identifiers = new List <string>()
                    {
                        node.Member.Name
                    }
                };
                _stack.Push(columnReference);
                return(node);
            }

            throw new NotSupportedException(string.Format("The member '{0}' is not supported", node.Member.Name));
        }
Ejemplo n.º 3
0
        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);
        }