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());
可以通过这个包直接构建表达式树。