Rule Expressions and short circuit evaluation #446
-
I found that for the following expression, the engine tries to evaluate the entire expression instead of performing a short circuit evaluation. Is this by design? Expression: Error Returned: InputMessage: notice there's no "missingProp" property in input1 message input1.telemetryType == 'weather' AND input1.windSpeed > 100 Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
also I was looking to be able to handle short circuit evaluation by using nested rules and the OrElse operator... |
Beta Was this translation helpful? Give feedback.
-
@bmasotta-lcg Short circuiting using nested rules works only if you enable perf mode in ReSettings. You can refer this example. RulesEngine/test/RulesEngine.UnitTest/NestedRulesTest.cs Lines 21 to 65 in 7b4e45d Also, on your earlier question, if you could provide me more details on how you are passing the input (and the type of it). I might be able to help you better. |
Beta Was this translation helpful? Give feedback.
-
I was unable to handle missing or null values on dynamic types without using nested rules or separate workflows. While I create rules that look for always-present properties on dynamic type inputs I don't have any problem (that's similar to work with static types) But if I need to work with dynamic or changing schemas in dynamic input messages and test for null on a specific field value, by using any kind of short circuit evaluation method, the RulesEngine will raise an error related to the expression evaluation.
}, "Expression": "input1.value != null AndAlso input1.value == 10", (https://dynamic-linq.net/advanced-null-propagation) "Expression": "(input1.value == null ? 0 : input1.value) == 10", One thing to add is that I find very confusing mentioning in the readme file that the rule expressions are similar to regular c# lambda expression. This is not true. The RulesEngine is silently using the https://dynamic-linq.net library, a library that looks like official .NET due to the namespace it uses, but it has it's own syntax, not the same syntax as for lamba expressions |
Beta Was this translation helpful? Give feedback.
@bmasotta-lcg Short circuiting using nested rules works only if you enable perf mode in ReSettings. You can refer this example.
RulesEngine/test/RulesEngine.UnitTest/NestedRulesTest.cs
Lines 21 to 65 in 7b4e45d