您的位置:首页 > 其它

字符串作为判断条件

2016-05-09 10:27 381 查看
首先引用一个DynamicQueryable类

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: