C#规则带有带有自定义规则的表达树的引擎

发布于 2025-01-24 14:58:19 字数 972 浏览 2 评论 0原文

我希望使用从此处给出的示例开始使用表达式树创建一个简单的规则引擎: https://www.psclistens.com/insight/blog/blog/quickly-build-build-a-build-a-business-engine-engine-engine-engine-angine-using-c- using-c-- and-lambda-expression-Trees/

在示例中,作者使用以下代码构造规则:

 // Create some rules using LINQ.ExpressionTypes for the comparison operators
 new Rule ( "Year", ExpressionType.GreaterThan, "2012"),
 new Rule ( "Make", ExpressionType.Equal, "El Diablo"),
 new Rule ( "Model", ExpressionType.Equal, "Torch" )

所使用的表达式是简单的比较操作。如何使用此示例可以按照以下方式创建一个规则:

  1. 新规则(“模型”,scressionType.isin,{“ ab”,“ ac”,“ ad”,“ ad”})
  2. 新规则(“模型”,scressiveType。包含“包含值”)
  3. 新规则{“ model”,cressiveType.istrue,somefuncthatreturnsbool(param))

是否可以给出以上的任何一个给定的示例?

tia

I am looking to create a simple rules engine using expression trees starting from the example given here: https://www.psclistens.com/insight/blog/quickly-build-a-business-rules-engine-using-c-and-lambda-expression-trees/

In the example, the author constructs rules using the following code:

 // Create some rules using LINQ.ExpressionTypes for the comparison operators
 new Rule ( "Year", ExpressionType.GreaterThan, "2012"),
 new Rule ( "Make", ExpressionType.Equal, "El Diablo"),
 new Rule ( "Model", ExpressionType.Equal, "Torch" )

The Expressions used are simple comparison ops. How might one, using this sample, create a rule along the lines of:

  1. new Rule ( "Model", ExpressionType.IsIn, {"AB", "AC", "AD"} )
  2. new Rule ( "Model", ExpressionType.Contains, "ContainedValue")
  3. new Rule { "Model", ExpressionType.IsTrue, SomeFuncThatReturnsBool(Param))

Are any of the above possible given the example cited?

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文