首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

关于动态Func<T,bool>的有关问题

2012-02-04 
关于动态FuncT,bool的问题请问各位大大,我要根据Type type xx。getType() 的type动态构建一个LambdaExp

关于动态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()方法。
[解决办法]
不懂帮顶。

热点排行