How to implement a rule engine?

后端 未结 10 1960
借酒劲吻你
借酒劲吻你 2020-11-27 23:58

I have a db table that stores the following:

RuleID  objectProperty ComparisonOperator  TargetValue
1       age            \'greater_than\'             15
2          


        
10条回答
  •  野性不改
    2020-11-28 00:25

    Although the most obvious way to answer the "How to implement a rule engine? (in C#)" question is to execute a given set of rules in sequence, this is in general considered as a naïve implementation (does not mean it does not work :-)

    It seems it's "good enough" in your case because your problem seems more to be "how to run a set of rules in sequence", and the lambda/expression tree (Martin's answer) is certainly the most elegant way in that matter if you are equiped with recent C# versions.

    However for more advanced scenarios, here is a link to the Rete Algorithm that is in fact implemented in many commercial rule engine systems, and another link to NRuler, an implementation of that algorithm in C#.

提交回复
热议问题