microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.6k stars 543 forks source link

Using generic method in expression does not work #505

Closed goodstas closed 1 year ago

goodstas commented 1 year ago

Hello, i wrote a small demo project where i defined rule as follows : { "ErrorMessage": "There is no forecast with temperature > 100C.", "ErrorType": "Error", "Expression": "dataStore.GetObjects(\"temperatureC > 100\").Count > 0", "RuleExpressionType": "LambdaExpression", "RuleName": "ForecastAbove100", "SuccessEvent": "There is at least one forecast with temperature > 100C" }

After rule's execution and investigation of the RuleResultTree i see an exception : "Exception while parsing expression dataStore.GetObjects<WeatherForecast>(\"temperatureC > 100\").Count > 0 - No property or field 'GetObjects' exists in type 'RedisObjectsManager'"

dataStore - i provide programmatically the instance of RedisObjectsManager as a RuleParameter and the type RedisObjectsManager i provided to the RuleEngine through custom types of ReSettings .

I tried to use regular method of the RedisObjectsManager (not generic one) and it works fine.

Are generic methods not available in the expressions? or there is a bug? Thank you.

@abbasc52

abbasc52 commented 1 year ago

Generic methods are not currently supported in expression. You can create a utils class and wrap the generic method call inside it.

goodstas commented 1 year ago

Thank you. @abbasc52