public Expression BuildExpression(Type type, Operator ruleOperator, object value, ParameterExpression parameterExpression)
        {
            ExpressionType expressionType      = new ExpressionType();
            var            leftOperand         = parameterExpression;
            var            rightOperand        = Expression.Constant(Convert.ChangeType(value, type));
            var            expressionTypeValue = (ExpressionType)expressionType.GetType().GetField(Enum.GetName(typeof(Operator), ruleOperator)).GetValue(ruleOperator);

            return(CastBuildExpression(expressionTypeValue, value, leftOperand, rightOperand));
        }
示例#2
0
        public Expression BuildExpression <T>(string propertyName, Operator ruleOperator, object value, ParameterExpression parameterExpression)
        {
            ExpressionType expressionType      = new ExpressionType();
            var            leftOperand         = MemberExpression.Property(parameterExpression, propertyName);
            var            rightOperand        = Expression.Constant(Convert.ChangeType(value, value.GetType()));
            FieldInfo      fieldInfo           = expressionType.GetType().GetField(Enum.GetName(typeof(Operator), ruleOperator));
            var            expressionTypeValue = (ExpressionType)fieldInfo.GetValue(ruleOperator);

            return(CastBuildExpression(expressionTypeValue, value, leftOperand, rightOperand));
        }
示例#3
0
        public Expression BuildSubExpression(Operator ruleOperator,
                                             Expression leftExpression,
                                             Expression rightExpression)
        {
            ExpressionType expressionType      = new ExpressionType();
            FieldInfo      fieldInfo           = expressionType.GetType().GetField(Enum.GetName(typeof(Operator), ruleOperator));
            var            expressionTypeValue = (ExpressionType)fieldInfo.GetValue(ruleOperator);

            if (ruleOperator == Operator.Not)
            {
                return(Expression.Not(leftExpression));
            }
            if (ruleOperator == Operator.IsTrue)
            {
                return(Expression.IsTrue(leftExpression));
            }
            return(Expression.MakeBinary(expressionTypeValue, leftExpression, rightExpression));
        }