问题描述
有谁知道一个好的 .NET 库规则库(最好是开源的)?我需要一些可以执行嵌套逻辑表达式的东西,例如 (A AND B) AND (B OR C OR D).我需要对对象属性进行比较,例如 A.P1 AND B.P1.(理想情况下,我可以比较任何属性——A.P1 和 B.P2).
Does anyone know of a good .NET library rules library (ideally open-source)? I need something that can do nested logic expressions, e.g., (A AND B) AND (B OR C OR D). I need to do comparisons of object properties, e.g., A.P1 AND B.P1. (Ideally, I could compare any property -- A.P1 AND B.P2).
它应该将规则存储在数据库中(我有很多简单的可配置逻辑).它应该有一个规则创建/管理 API.管理工具必须检查实例以确定哪些属性可用以及存在哪些约束.
It should store the rules in a database (I've got a lot of simple configurable logic). And it should have a rule creation/management API. The management tool would have to inspect the instances to determine which properties are available and which constraints exist.
谢谢!
哦,还有一件事.作为规则引擎,我需要包含操作(命令)的概念.这些是表达式返回时执行的内容:
Oh, one more thing. As a rules-engine, I need to include the concept of Actions (Commands). These are what execute when the expression returns:
If (expression.Evaluation) { actions.Execute(); }
所以我认为规则是这样的:
So I see a rule as something like:
class Rule
{
Expression Exp;
Actions[] Actions;
Run()
{
if(Exp.Evaluate())
{
foreach(action in Actions)
{
action.Execute();
}
}
}
}
推荐答案
同意我会说使用工作流引擎系列中的东西,尽管不是工作流.检查 System.Workflow.Activities.Rules 命名空间一点点 - 它在 .Net 3 中受支持,并内置于 .Net3.5 中.就像您提到的那样,您可以免费使用所有东西:
Agreeing with will I would say use something from the workflow engine family although not workflow.Examine System.Workflow.Activities.Rules Namespace a little bit - it's supported in .Net 3, and built into .Net3.5. You have everything in hand for free to use like you mentioned :
RuleCondition 用于条件,RuleAction 用于操作
RuleCondition for conditions , RuleAction for actions
用于描述的标准化格式元代码(CodeDom - CodeExpressions)
standardized format for describingmetacode (CodeDom - CodeExpressions)
您可以插入任何类型的复杂性进入那个(说实话,除了Linq 和 lambdas 等扩展某种方法)通过类型提供者
you can plugin any kind of complexityinto that (to tell the truth exceptLinq and lambdas and so extensionmethods of some kind) viaTypeProviders
有一个内置的规则编辑器使用智能感知编辑
there's a builtin editor for ruleediting with intellisense
因为规则是可序列化的,所以它可以是容易坚持
as the rule is serializable it can beeasily persisted
对于初学者:在工作流之外使用规则
Ps.:我们正在广泛使用它,并且该命名空间中的内容比您想象的要多得多 -> 一种完整的元算法语言
Ps.: we're using it extensively and there're much more in that namespace than you ever imagine -> a complete meta algorithm language
最重要的是:它易于使用 - 真的
And the most important : it's easy to use - really
这篇关于在 .NET 中寻找简单的规则引擎库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!