microsoft / RulesEngine

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

Support for Any-Operator on List-Types #598

Open Steinliiippp opened 3 months ago

Steinliiippp commented 3 months ago

Are there any plans to support access to properties on Lists like resource.Users.Name? Currently you get the exception "No property or field 'Name' exists in type 'List`1'". Which directs me to the problem, that the MemberExpression builder does not note the List-Type and tries to just build the expression just as usually.

At this point we would need an interception to the Any-Method and then build the nested (Sub)Expression for the generic type of the list. Afterwards it needs to be set as expression to the Any-Method call of the List (Users).

Are there any plans to support this? Maybe for the first level or even for nested lists with chained Any-Method-Calls?

sebastianwhiffen commented 2 months ago

I am also interested in this, currently getting this error

{ "rule": { "ruleName": "SecurityValidation", "properties": null, "operator": null, "errorMessage": "Error message", "enabled": true, "ruleExpressionType": 0, "workflowsToInject": null, "rules": null, "localParams": null, "expression": "securities.Any(security => security.objId == 2576460 )", "actions": null, "successEvent": "Success event" }, "isSuccess": false, "childResults": null, "inputs": { "JsonElement": { "securities": [ { "loanId": "M305666", "objId": 2576460, //theres more } ], "needVehicleInspection": false } }, "actionResult": { "output": null, "exception": null }, "exceptionMessage": "Exception while parsing expression securities.Any(security => security.objId == 2576460) - ')' or ',' expected" }

timophe-91 commented 1 week ago

Any, All, .. is part of the Enumerable Class, i just registered that and it worked for me.

CustomTypes = [ typeof(Enumerable) ]