linq自定义条件Lambda过滤方法

Public Func<NoramalClass,bool>simpleComare<NormalClass>(string property,object value)

{

var type=typeof(NoramalClass);

var pe=Expression.Parameter(type,"p");

var propertyReference=Expression.Propery(pe,property);

var constantReferecnce=Expression.Constant(value);

return Expression.Lambda<Func<NormalClass,boo>>(Expression.Equal(propertyReferecnce,constantReferecnce),pe).Compile();

}

 

//查询某一列

Public Func<NoramalClass,string>simpleComare<NormalClass>(string property)

{

var type=typeof(NoramalClass);

var pe=Expression.Parameter(type,"p");

var propertyReference=Expression.Propery(pe,property);

return Expression.Lambda<Func<NormalClass,string>>(propertyReferecnce,pe).Compile();

}

posted @ 2019-07-20 10:49  领悟.海洋  阅读(783)  评论(0编辑  收藏  举报