ValidatableModel does not list all validation errors
jbe2277 opened this issue · 1 comments
jbe2277 commented
ValidatableModel
does not list all validation errors when following is true:
- Object has validation errors found by validation attributes
- Object implements the
IValidatableObject
interface and this implementation returns additional validation errors
In this situationValidatableModel
lists only the validation errors found by validation attributes and skips the errors found byIValidatableObject
.
This is an issue of .NET. See: Add variant for Validator.TryValidateObject which provides all validation errors
jbe2277 commented
System.Waf.Core 6.1 introduces the ValidationHelper
class which sovles this issue. It provides the method:
public static IEnumerable<ValidationResult> Validate(object instance)
This method is similar to Validator.TryValidateObject(object, ValidationContext, ICollection<ValidationResult>, bool) with following adaptions:
- Returns always all found validation errors
- Simplified API
- Does not support passing of a ValidationContext. This is not really needed.
- Always validates all properties. Flag is not needed.
- Implementation is about 30% faster
- New implementation needs just about 50% LoC of the original one.
- The returned IEnumerable reads the errors on demand. Operations like
Any()
are very fast.
The ValidatableModel
is using the new implementation starting with version 6.1.