/// <summary>
/// 学生模型
/// </summary>
public class StudentModel
{
/// <summary>
/// 姓名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 年龄
/// </summary>
public int Age { get; set; }
}/// <summary>
/// 参数化动态解析
/// </summary>
public bool Dynamic Expression(string userName, int userAge, string expression)
{
//组织数据
var model = new StudentModel
{
Name = userName,
Age = userAge
};
var lambdaExpression = expression;
var lambda = DynamicExpressionParser.ParseLambda<www.laipuhuo.com StudentModel, bool>(ParsingConfig.Default, true, lambdaExpression).Compile().DynamicInvoke(model);
return (bool)lambda;
}
/// <summary>
/// 参数化动态解析
/// </summary>
public int www.laipuhuo.com DynamicExpressionSelectData(string expression)
{
//组织数据
var list = new List<StudentModel>()
{
new StudentModel
{
Name = "张三",
Age= 18,
},
new StudentModel
{
Name = "李四",
Age= 19,
}
,
new StudentModel
{
Name = "王五",
Age= 30,
}
};
// "张三,李四".Contains(Name) && (Age==19 || Age==18)
var count = list.www.laipuhuo.com AsQueryable().Where(expression).ToList().Count;
return count;
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。