Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuleParameter.Name == "Acceptor" causes Exception on rule #549

Closed
mpcham opened this issue Nov 7, 2023 · 0 comments · Fixed by #554
Closed

RuleParameter.Name == "Acceptor" causes Exception on rule #549

mpcham opened this issue Nov 7, 2023 · 0 comments · Fixed by #554

Comments

@mpcham
Copy link

mpcham commented Nov 7, 2023

The below example results in an Exception: "Exception while parsing expression !string.IsNullOrEmpty(Acceptor.Company) - No property or field 'Company' exists in type 'Acceptor'"

`List rules = new List();

Rule rule = new Rule();
rule.RuleName = "Test Rule";
rule.SuccessEvent = "true";
rule.ErrorMessage = "Test Error";
rule.Expression = "!string.IsNullOrEmpty(Acceptor.Company)";
rule.RuleExpressionType = RuleExpressionType.LambdaExpression;
rules.Add(rule);

var workflows = new List();

Workflow exampleWorkflow = new Workflow();
exampleWorkflow.WorkflowName = "Example Workflow";
exampleWorkflow.Rules = rules;

workflows.Add(exampleWorkflow);

Acceptor ap = new();
ap.Company = "";

List ruleParams2 = new();
ruleParams2.Add(new RuleParameter("Acceptor", ap));

var re = new RulesEngine.RulesEngine(workflows.ToArray());

var result = await re.ExecuteAllRulesAsync("Example Workflow", ruleParams2.ToArray());`

Changing the Rule Parameter Name to pAcceptor executes successfully with no exception. Successful code below... not sure why the word acceptor breaks the expression but it does...

`List rules = new List();

Rule rule = new Rule();
rule.RuleName = "Test Rule";
rule.SuccessEvent = "true";
rule.ErrorMessage = "Test Error";
rule.Expression = "!string.IsNullOrEmpty(pAcceptor.Company)";
rule.RuleExpressionType = RuleExpressionType.LambdaExpression;
rules.Add(rule);

var workflows = new List();

Workflow workFlow = new Workflow();
workFlow.WorkflowName = "Example Workflow";
workFlow.Rules = rules;

workflows.Add(workFlow);

Acceptor ap = new();
ap.FirstName = "";
ap.LastName = "";
ap.Company = "";

List rParameters = new();
rParameters.Add(new RuleParameter("pAcceptor", ap));

var re = new RulesEngine.RulesEngine(workflows.ToArray());

var r = await re.ExecuteAllRulesAsync("Example Workflow", rParameters.ToArray());`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant