字符串作为判断条件
2016-05-09 10:27
381 查看
首先引用一个DynamicQueryable类
View Code
using System; using System.Collections.Generic; using System.Linq.Dynamic; using System.Windows.Forms; using System.Linq; namespace Demo { public partial class Form8 : Form { public Form8() { InitializeComponent(); } public static readonly Func<Test, string, bool> ConditionFunc = (t, s) => DynamicQueryable.Where((new List<Test> { t }).AsQueryable(), s).Any(); private void Form8_Load(object sender, EventArgs e) { bool flag = false; Test t1 = new Test(); t1.Id = 1; t1.Name = "a"; var whereRule = "Name==\"G\""; flag = ConditionFunc(t1, whereRule); if (!flag) { MessageBox.Show("111"); } else { MessageBox.Show("222"); } } } public class Test { private int id; private string name; public int Id { get { return this.id; } set { this.id = value; } } public string Name { get { return this.name; } set { this.name = value; } } } }
View Code
相关文章推荐
- Entity Framework 5.0 Code First全面学习
- -XX:+PrintGCTimeStamps 打印CG发生的时间戳
- Leetcode 322 Coin Change
- loadrunner录制时弹出invalid application path!please check if application exists对话框
- 提交图片到svn
- 页面左右分布方案调整
- 专访|腾讯、阿里、adidas的服务方UID WORKS
- 漫游场景
- Timer定时器
- PHP面向对象的进阶学习(抽像类、接口、final、类常量)
- Android SDK版本号与API级别的对应关系以及创建工程时选择API版本的注意事项
- -XX:+PrintGCDetails 打印GC详细信息
- Java生成随机数
- select 列值操作
- 数据库用户权限
- AJAX入门
- Spring-boot构建
- sdutoj 3252 Lowest Unique Price
- 监听软键盘的显示与隐藏
- Bat命令学习 (转载)