示例#1
0
        private Expression ParaseBetween(ParameterExpression parameter, UosoConditions conditions)
        {
            ParameterExpression p   = parameter;
            Expression          key = Expression.Property(p, conditions.Key);

            var valueArr = conditions.Value.ToString().Split(',');

            if (valueArr.Length != 2)
            {
                throw new NotImplementedException("ParaseBetween参数错误");
            }
            try
            {
                int.Parse(valueArr[0]);
                int.Parse(valueArr[1]);
            }
            catch
            {
                throw new NotImplementedException("ParaseBetween参数只能为数字");
            }
            Expression expression = Expression.Constant(true, typeof(bool));
            //开始位置
            Expression startvalue = Expression.Constant(int.Parse(valueArr[0]));
            Expression start      = Expression.GreaterThanOrEqual(key, Expression.Convert(startvalue, key.Type));

            Expression endvalue = Expression.Constant(int.Parse(valueArr[1]));
            Expression end      = Expression.GreaterThanOrEqual(key, Expression.Convert(endvalue, key.Type));

            return(Expression.AndAlso(start, end));
        }
示例#2
0
        private Expression ParaseIn(ParameterExpression parameter, UosoConditions conditions)
        {
            ParameterExpression p   = parameter;
            Expression          key = Expression.Property(p, conditions.Key);
            var        valueArr     = conditions.Value.ToString().Split(',');
            Expression expression   = Expression.Constant(true, typeof(bool));

            foreach (var itemVal in valueArr)
            {
                Expression right;
                Expression value = Expression.Constant(itemVal);
                if (key.Type.ToString() == "System.Int32")
                {
                    if (itemVal == "")
                    {
                        value = Expression.Constant(-1);
                    }
                    right = Expression.Equal(key, Expression.Convert(value, key.Type));
                }
                else
                {
                    right = Expression.Equal(key, Expression.Convert(value, key.Type));
                }
                Expression.Or(expression, right);
            }
            return(expression);
        }
示例#3
0
        private Expression ParseCondition(UosoConditions condition)
        {
            ParameterExpression p     = parameter;
            Expression          key   = Expression.Property(p, condition.Key);
            Expression          value = Expression.Constant(condition.Value);

            switch (condition.OperatorMethod)
            {
            case "Contains":
                return(Expression.Call(key, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), value));

            case "Equal":
                return(Expression.Equal(key, Expression.Convert(value, key.Type)));

            case "Greater":
                return(Expression.GreaterThan(key, Expression.Convert(value, key.Type)));

            case "GreaterEqual":
                return(Expression.GreaterThanOrEqual(key, Expression.Convert(value, key.Type)));

            case "Less":
                return(Expression.LessThan(key, Expression.Convert(value, key.Type)));

            case "LessEqual":
                return(Expression.LessThanOrEqual(key, Expression.Convert(value, key.Type)));

            case "NotEqual":
                return(Expression.NotEqual(key, Expression.Convert(value, key.Type)));

            case "In":
                return(ParaseIn(p, condition));

            case "Between":
                return(ParaseBetween(p, condition));

            default:
                throw new NotImplementedException("不支持此操作");
            }
        }