CustomValidationAttribute specifed method not being called

后端 未结 1 958
终归单人心
终归单人心 2021-01-03 04:29

I\'m using the System.ComponentModel.DataAnnotations.CustomValidationAttribute to validate one of my POCO classes and when I try to unit test it, it\'s not even calling the

相关标签:
1条回答
  • 2021-01-03 04:51

    Try using the overload that takes a bool that specifies if all properties should be validated. Pass true for the last parameter.

    public static bool TryValidateObject(
        Object instance,
        ValidationContext validationContext,
        ICollection<ValidationResult> validationResults,
        bool validateAllProperties
    )
    

    If you pass false or omit the validateAllProperties, only the RequiredAttribute will be checked. Here is the MSDN documentation.

    0 讨论(0)
提交回复
热议问题