Пример #1
0
        private Expression GetExpression(ParameterExpression param, ConditionItem item)
        {
            //属性表达式
            LambdaExpression exp = GetPropertyLambdaExpression(item, param);

            //如果有特殊类型处理,则进行处理,暂时不关注
            foreach (var provider in TransformProviders)
            {
                if (provider.Match(item, exp.Body.Type))
                {
                    return(GetGroupExpression(param, provider.Transform(item, exp.Body.Type), Expression.AndAlso));
                }
            }
            //常量表达式
            var constant = ChangeTypeToExpression(item, exp.Body.Type);

            //以判断符或方法连接
            return(ExpressionDict[item.Method](exp.Body, constant));
        }
Пример #2
0
        private LambdaExpression GetPropertyLambdaExpression(ConditionItem item, ParameterExpression param)
        {
            //获取每级属性如c.Users.Proiles.UserId
            var        props          = item.Field.Split('.');
            Expression propertyAccess = param;
            var        typeOfProp     = typeof(T);
            int        i = 0;

            do
            {
                PropertyInfo property = typeOfProp.GetProperty(props[i]);
                if (property == null)
                {
                    return(null);
                }
                typeOfProp     = property.PropertyType;
                propertyAccess = Expression.MakeMemberAccess(propertyAccess, property);
                i++;
            } while (i < props.Length);

            return(Expression.Lambda(propertyAccess, param));
        }