我希望使用Rule#在我的应用程序中使用NRules引擎编写规则。由于我希望用户在运行时编写他们的规则,我想知道是否可以这样做。
When()
.Match<Customer>(() => customer)
.Exists<Order>(o => o.Customer == customer, o => o.PercentDiscount > 0.0);
Then()
.Do(_ => customer.NotifyAboutDiscount());使用Rule#?
这里的示例https://github.com/NRules/NRules.Language向我展示了如何使用单个对象创建一个或多个规则。但是,我想在一条规则中使用不同的类对象,如上面的示例所示。
我找不到关于Rule#的更详细的文档.
发布于 2022-11-21 00:50:58
需要注意的是,与内部规则DSL相比,Rule# (又名NRules.Language)功能不完整。查看Rule#中当前支持的所有示例的最佳地方是集成测试:https://github.com/NRules/NRules.Language/blob/develop/src/NRules.RuleSharp/NRules.RuleSharp.IntegrationTests/RuleCompilerTests.cs
特别地,对于您的示例,假设域模型包含具有相应属性和方法的Customer和Order类型,规则如下所示:
rule "Notify About Discount"
when
var customer = Customer();
exists Order(o => o.Customer == customer, o => o.PercentDiscount > 0.0);
then
customer.NotifyAboutDiscount();https://stackoverflow.com/questions/74506528
复制相似问题