Beispiel #1
0
        public bool ValidateProperties()
        {
            var propertiesWithChangedErrors = new List <string>();

            // Get all the properties decorated with the ValidationAttribute attribute.
            if (PropertyInfos != null)
            {
                foreach (PropertyInfo propertyInfo in PropertyInfos)
                {
                    var propertyErrors = new List <string>();
                    TryValidateProperty(propertyInfo, propertyErrors);

                    // If the errors have changed, save the property name to notify the update at the end of this method.
                    ErrorsContainer.SetErrors(propertyInfo.Name, propertyErrors);
                }
            }

            var propertiesToValidate = this.GetType()
                                       .GetRuntimeProperties()
                                       .Where(c => c.GetCustomAttributes(typeof(ValidationAttribute)).Any());

            foreach (PropertyInfo propertyInfo in propertiesToValidate)
            {
                var propertyErrors = new List <string>();
                TryValidateProperty(propertyInfo, propertyErrors);

                // If the errors have changed, save the property name to notify the update at the end of this method.
                ErrorsContainer.SetErrors(propertyInfo.Name, propertyErrors);
            }

            return(ErrorsContainer.HasErrors);
        }
Beispiel #2
0
 public Dictionary <string, List <string> > GetAllErrors()
 {
     return(ErrorsContainer.GetAllErrors());
 }
Beispiel #3
0
 public void SetErrors <TProperty>(Expression <Func <TProperty> > propertyExpression, IEnumerable <string> errors)
 {
     ErrorsContainer.SetErrors(propertyExpression, errors);
 }
Beispiel #4
0
 public IEnumerable GetErrors(string propertyName)
 {
     return(ErrorsContainer.GetErrors(propertyName));
 }