net-core(DynamicExpresso.Core)

==============================(Install - Package DynamicExpresso.Core)======================================

var whereExpression = $"m.{queryField}==\"{queryValue}\"";

string whereExpression = "customer.Age > 18 && customer.Gender == 'F'";

var interpreter = new Interpreter();
Func<Customer, bool> dynamicWhere = interpreter.ParseAsDelegate<Func<Customer, bool>>(whereExpression, "customer");

Assert.AreEqual(1, customers.Where(dynamicWhere).Count());

=====================================================================================================
string whereExpression = "customer.Age > 18 && customer.Gender == 'F'";

var interpreter = new Interpreter();
Expression<Func<Customer, bool>> expression = interpreter.ParseAsExpression<Func<Customer, bool>>(whereExpression, "customer");

Assert.AreEqual(1, customers.Where(expression).Count());

可以通过这个包直接构建表达式树。

posted @ 2023-07-12 17:57  vba是最好的语言  阅读(66)  评论(0编辑  收藏  举报