Validation messages restricted to static strings

Jul 7, 2014 at 4:19 PM
Since data contracts preconditions had been added in version 2 I realized that there si quite significant limitation - error message has to be known at the time rule is defined instead of the rule execution.

It's not that uncommon to have validation logic that composes error logic at runtime.
I would add a variation of AddRule that accepts Func<string> as error message.

Another concern i have is that validation takes much more time i would expect.
I have a grid row viewmodel object with roughly 20 simple rules (mostly property comparisons) and ValidateAll takes between 70 and 200 ms. I haven't noticed that previously but now i'm facing serious scalability issues as i may need to validate 1000s rows at once.
Jul 7, 2014 at 4:48 PM
Not sure what you mean when you say validation messages are restricted to static strings. Take a look at the example of how to add a rule:
Validator.AddRule(() => FirstName, () => RuleResult.Assert(!string.IsNullOrEmpty(FirstName), "First Name is required"));
You see that the second parameter is a function. That function is executed every time the validation is performed, so you can generate the error message at run time.

Regarding your concern about performance, I will try to do some performance tests. It would be great if you could also try to profile your application and see what exactly takes so long.