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

Custom Name of Parameter not being honored. #581

Open khPhoenix opened 4 months ago

khPhoenix commented 4 months ago

When trying to specify a custom name for a parameter we are receiving the following error:

Parameter Declaration:

var wfParams = new MyParam()
{
    Value1 = "value1",
    Value2 = "value2"
};
var rp = new RuleParameter("myValue", wfParams); 

var myWorkflow = new Workflow
{
    WorkflowName = "my_workflow",
    Rules = new List<Rule>
    {
        new Rule
        {
            RuleName = "MatchesFabrikam",
            Enabled = true,
            RuleExpressionType = RuleExpressionType.LambdaExpression,
            Expression = "myValue.Value1== \"Fabrikam\""
        }
    }
};

When the rule is evaluated the following error is received:

  Message: 
System.Exception : Could not execute rules: [MatchesFabrikam: Exception while parsing expression `myValue.Value1 == "Fabrikam"` - Enum type 'endpoint' not found]`

We're targeting .net8 and using RulesEngine 5.0.2.

abbasc52 commented 4 months ago

@khPhoenix can you share MyParam class definition?

khPhoenix commented 4 months ago

@abbasc52

public class MyParam
{
    public string? Value1 { get; set; }
    public string? Value2 { get; set; }
}
asulwer commented 5 days ago

i added a working example and solution to my fork