コード例 #1
0
 public void ClearValidationErrors <T>(T instance)
 {
     ValidationDone?.Invoke(this,
                            new ValidationErrorEventArgs()
     {
         Errors         = new List <ValidationResult>(),
         ValidationType = GetValidationType <T>(instance)
     });
 }
コード例 #2
0
        public bool Validate <T>(T instance)
        {
            List <ValidationResult> res = new List <ValidationResult>();
            bool isValid = Validator.TryValidateObject(instance, new ValidationContext(instance), res, true);

            ValidationDone?.Invoke(this,
                                   new ValidationErrorEventArgs()
            {
                Errors         = res,
                ValidationType = GetValidationType <T>(instance)
            });

            return(isValid);
        }
コード例 #3
0
        public void NotifyAboutServerErrors <T>(T instance, ValidationErrors serverErrors)
        {
            List <ValidationResult> errors = new List <ValidationResult>();

            foreach (string key in serverErrors.Errors.Keys)
            {
                foreach (string error in serverErrors.Errors[key])
                {
                    errors.Add(new ValidationResult(error, new string[] { key }));
                }
            }

            ValidationDone?.Invoke(this,
                                   new ValidationErrorEventArgs()
            {
                Errors         = errors,
                ValidationType = GetValidationType <T>(instance)
            });
        }