p => ((((True And (p.Name.ToString() = "JT")) And (p.Sex.ToString() = "男")) And (p.Age.ToString() = "20")) And (p.Birthday.ToString() = "02/02/2008"))
new ConstructLambda<Person>().GetOrLambdaExpression(dictionary).ToString()返
回结果:
p => ((((False Or (p.Name.ToString() = "JT")) Or (p.Sex.ToString() = "男")) Or (p.Age.ToString() = "20")) Or (p.Birthday.ToString() = "02/02/2008"))
//构造常量表达式
Expression expression_return = Expression.Constant(true);
//构造表达式参数 类似于p=> 中的p
ParameterExpression expression_param = Expression.Parameter(TType, "p");
//遍历所有关键词 生成查询条件
foreach (string key in dictionary.Keys)
{
//生成类似与“p.Name.ToString()==常量”的表达式
Expression temp = Expression.Equal(
//后面两行先用.Property 得到p.Name 然后用call得到p.Name.ToString();
Expression.Call(
Expression.Property(expression_param, TType.GetProperty(key)),TType.GetMethod("ToString")),
Expression.Constant(dictionary[key]));
//合并查询条件
expression_return = Expression.And(expression_return, temp);
}