C# 规则:匹配集合
我正在尝试找出BRE规则,并获得了一些有效的示例,但很难匹配一个集合C# 规则:匹配集合,c#,rete,nrules,C#,Rete,Nrules,我正在尝试找出BRE规则,并获得了一些有效的示例,但很难匹配一个集合 IEnumerable<Order> orders = null; When() .Match<IEnumerable<Order>>(o => o.Where(c => c.Cancelled).Count() >= 3) .Collect<Order>(() => orders, o => o.Cancelled); Then
IEnumerable<Order> orders = null;
When()
.Match<IEnumerable<Order>>(o => o.Where(c => c.Cancelled).Count() >= 3)
.Collect<Order>(() => orders, o => o.Cancelled);
Then()
.Do(ctx => orders.ToList().ForEach(o => o.DoSomething()));
我在这里做错了什么?在您的示例中,应该非常简单
IEnumerable<Order> orders = null;
When()
.Collect<Order>(() => orders, o => o.Cancelled == true);
Then()
.Do(ctx => orders.ToList().ForEach(o => o.DoSomething()));
IEnumerable orders=null;
当()
.Collect(()=>orders,o=>o.Cancelled==true);
然后()
.Do(ctx=>orders.ToList().ForEach(o=>o.DoSomething());
我认为重要的部分是o.Cancelled,而不是==true。我知道这听起来很奇怪,但不知何故,NRules中不支持单独的属性评估,它不是一个表达式(即仅属性)
我遇到了这个问题,当我添加==true时,一切都准备就绪。对于0.3.1版本的NRules,当您收集3个或更多取消的订单时,以下内容将激活该规则:
IEnumerable<Order> orders = null;
When()
.Collect<Order>(() => orders, o => o.Cancelled)
.Where(x => x.Count() >= 3);
Then()
.Do(ctx => orders.ToList().ForEach(o => o.DoSomething()));
IEnumerable orders=null;
当()
.收款(()=>订单,订单=>订单取消)
其中(x=>x.Count()>=3);
然后()
.Do(ctx=>orders.ToList().ForEach(o=>o.DoSomething());
更新:
对于后人来说,从版本0.4.x开始,正确的语法是使用反应式LINQ。匹配集合将如下所示:
IEnumerable<Order> orders = null;
When()
.Query(() => orders, q => q
.Match<Order>(o => o.Cancelled)
.Collect()
.Where(x => x.Count() >= 3));
Then()
.Do(ctx => DoSomething(orders));
IEnumerable orders=null;
当()
.Query(()=>订单,q=>q
.匹配(o=>o.取消)
.Collect()
其中(x=>x.Count()>=3));
然后()
.Do(ctx=>DoSomething(订单));
如何基于以下表达式加入多个集合:
IEnumerable<RawMsp> rawMsps = null;
IEnumerable<AsmMasterView> asmMasterViews = null;
IEnumerable<AsmInvestor> asmInvestors = null;
When()
.Match<AsmInvestor>(() => rawMsps)
.Match<AsmInvestor>(() => asmInvestor, i => i.InvestorId.ToString() == rawMsp.INVESTOR_CODE)
.Match<AsmMasterView>(() => asmMasterView, x => x.ChildAssumptionHistId == asmInvestor.AssumptionHistId);
IEnumerable rawMsps=null;
IEnumerable ASMMasterView=null;
IEnumerable=null;
当()
.Match(()=>rawMsps)
.Match(()=>asmInvestor,i=>i.InvestorId.ToString()==rawMsp.INVESTOR\u代码)
.Match(()=>asmMasterView,x=>x.ChildAssumptionHistId==asmInvestor.AssumptionHistId);
Match适用于单个对象,不确定apply是否等于可枚举对象谢谢,我明天会尝试一下,并让您知道。:)
IEnumerable<RawMsp> rawMsps = null;
IEnumerable<AsmMasterView> asmMasterViews = null;
IEnumerable<AsmInvestor> asmInvestors = null;
When()
.Match<AsmInvestor>(() => rawMsps)
.Match<AsmInvestor>(() => asmInvestor, i => i.InvestorId.ToString() == rawMsp.INVESTOR_CODE)
.Match<AsmMasterView>(() => asmMasterView, x => x.ChildAssumptionHistId == asmInvestor.AssumptionHistId);