private static Expression GetExpressionBody(ParameterExpression param, FilterGroup group)
        {
            param.CheckNotNull("param");

            //如果无条件或条件为空,直接返回 true表达式
            if (group == null || (group.Rules.Count == 0 && group.Groups.Count == 0))
            {
                return(Expression.Constant(true));
            }
            List <Expression> bodys = new List <Expression>();

            bodys.AddRange(group.Rules.Select(rule => GetExpressionBody(param, rule)));
            bodys.AddRange(group.Groups.Select(subGroup => GetExpressionBody(param, subGroup)));

            if (group.Operate == FilterOperate.And)
            {
                return(bodys.Aggregate(Expression.AndAlso));
            }
            if (group.Operate == FilterOperate.Or)
            {
                return(bodys.Aggregate(Expression.OrElse));
            }
            // throw new OSharpException(Resources.Filter_GroupOperateError); //helang
            return(null);
        }
Beispiel #2
0
        private static Expression GetExpressionBody(ParameterExpression param, FilterGroup group)
        {
            param.CheckNotNull("param");

            //如果无条件或条件为空,直接返回 true表达式
            if (group == null || (group.Rules.Count == 0 && group.Groups.Count == 0))
            {
                return(Expression.Constant(true));
            }
            List <Expression> bodys = new List <Expression>();

            bodys.AddRange(group.Rules.Select(rule => GetExpressionBody(param, rule)));
            bodys.AddRange(group.Groups.Select(subGroup => GetExpressionBody(param, subGroup)));

            if (group.Operate == FilterOperate.And)
            {
                return(bodys.Aggregate(Expression.AndAlso));
            }
            if (group.Operate == FilterOperate.Or)
            {
                return(bodys.Aggregate(Expression.OrElse));
            }
            throw new Exception("查询条件组中的操作类型错误,只能为And或者Or。");
        }