日期:2014-05-20  浏览次数:20821 次

关于动态Func<T,bool>的问题
请问各位大大,我要根据Type type = xx。getType() 的type动态构建一个LambdaExpression (因为type不同,筛选的字段也不同,构建的LambdaExpression是Func<T,bool>的)。但是where方法需要的是Func<T,bool>,我要怎么把我的LambdaExpression强转为Func<T,bool>啊?(主要是T不知怎么拿?)或者怎么动态构建Func<T,bool>?

------解决方案--------------------
string s = "name";
List<TestModel> lst = new List<TestModel>();
lst.Add(new TestModel() { name = "张三", id = "001", sex = "男" });
lst.Add(new TestModel() { name = "李四", id = "002", sex = "女" });
lst.Add(new TestModel() { name = "王五", id = "003", sex = "男" });
lst.Add(new TestModel() { name = "赵六", id = "004", sex = "男" });
PropertyInfo pi = typeof(TestModel).GetProperty(s);
List<TestModel> lstNew = lst.Where(p => pi.GetValue(p,null).ToString() == "张三").ToList();
http://topic.csdn.net/u/20110421/09/e2d0d178-cfed-4de2-8705-4bf6372daf88.html
------解决方案--------------------
LambdaExpression 转换 直接执行Compile()方法。
------解决方案--------------------
不懂帮顶。