LP13
LP13

Reputation: 34089

Microsoft's rule engine throws an exception if the input lacks the specified property

I am using Microsoft's rule engines. The issue arises when the expression references a property that does not exist in the input object, causing the RuleExpressionParser to throw an exception.

private bool Evaluate(string expression, ExpandoObject input)
{
    var ruleSettings = new ReSettings()
    {
        EnableExceptionAsErrorMessage = false,
        IgnoreException = false,
        IsExpressionCaseSensitive = false
    };
    var parser = new RuleExpressionParser(ruleSettings);


    return parser.Evaluate<bool>(expression, new RuleParameter[]
        {
        new RuleParameter("evalContext",input)
        });
}

var expression = "addressaddressee1_confidence > 0.75";
var input = new ExpandoObject();

var result = Evaluate(expression, input);

Is there any way to tell the parser to return false if the property does not exist in the input object?

Upvotes: 0

Views: 152

Answers (0)

Related Questions