private static LambdaExpression GetPropertyLambdaExpression(ParameterExpression param, FilterRule rule) { string[] propertyNames = rule.Field.Split('.'); Expression propertyAccess = param; Type type = param.Type; foreach (string propertyName in propertyNames) { PropertyInfo property = type.GetProperty(propertyName); if (property == null) { throw new InvalidOperationException(string.Format(Resources.Filter_RuleFieldInTypeNotFound, rule.Field, type.FullName)); } type = property.PropertyType; propertyAccess = Expression.MakeMemberAccess(propertyAccess, property); } return(Expression.Lambda(propertyAccess, param)); }
/// <summary> /// 获取指定查询条件的查询表达式 /// </summary> /// <typeparam name="T">表达式实体类型</typeparam> /// <param name="rule">查询条件,如果为null,则直接返回 true 表达式</param> /// <returns>查询表达式</returns> public virtual Expression <Func <T, bool> > GetExpression <T>(FilterRule rule) { return(FilterHelper.GetExpression <T>(rule)); }