Hi Rocky,
I just found an issue with the Lambda class. Please have a look on the code below:
protected override void AddBusinessRules()
{
var rule1 = new Lambda(MyPropertyInfo, context => context.AddErrorResult("Error"));
BusinessRules.AddRule(rule1);
var rule2 = new Lambda(MyPropertyInfo, context => {});
BusinessRules.AddRule(rule2);
}
By the code we can see BusinessRules.IsValid is always False when MyProperty changes. But in fact BusinessRules.IsValid is True. The reason is both rule1 and rule2 have the same RuleName. So when BusinessRules.CheckRules is called, the rule2's result (Success) overrides the rule1's result (Failed)
For resolving this issue, I suggest that you change the original code:
public Lambda(Action<RuleContext> rule)
{
Rule = rule;
base.RuleUri.AddQueryParameter("r", Rule.GetHashCode().ToString());
}
to
public Lambda(Action<RuleContext> rule)
{
Rule = rule;
base.RuleUri.AddQueryParameter("r", Rule.Method.GetHashCode().ToString());
}
or safer
public Lambda(Action<RuleContext> rule)
{
Rule = rule;
base.RuleUri.AddQueryParameter("r",
Convert.ToBase64String(Encoding.Unicode.GetBytes(Rule.Method.ToString())));
}
Thanks, that's clearly a bug, I'll add it to the list.
The fix will be in 4.0.1.
Copyright (c) Marimer LLC