Пример #1
0
        /// <summary>
        /// Determine whether the property should be validated from the ValidatePropertyMode setting.
        /// </summary>
        /// <param name="propertyName">Name of the property to validate.</param>
        /// <returns><c>true</c> if the property should be validated; otherwise <c>false</c>.</returns>
        protected bool ShouldValidateProperty(string propertyName)
        {
            if (ValidatePropertyMode == ValidatePropertyMode.Never)
            {
                return(false);
            }

            if (ValidatePropertyMode == ValidatePropertyMode.HasError &&
                ErrorsContainer.GetErrors(propertyName).Any() == false)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Validates this instance's properties.
        /// </summary>
        /// <param name="updateDisplay">if set to <c>true</c> the display is notified.</param>
        /// <returns><c>true</c> if the instance is valid.</returns>
        public virtual bool Validate(bool updateDisplay)
        {
            var vc      = new ValidationContext(this, null, null);
            var results = new List <ValidationResult>();
            var isValid = Validator.TryValidateObject(this, vc, results, true);

            if (!updateDisplay)
            {
                return(isValid);
            }

            if (isValid)
            {
                ErrorsContainer.ClearErrors();
            }
            else
            {
                ErrorsContainer.SetErrors(results);
            }

            OnValidationComplete();
            return(isValid);
        }
Пример #3
0
 /// <summary>
 /// Gets the error message for the property with the given name.
 /// </summary>
 /// <returns>The error message for the property. The default is an empty string ("").</returns>
 string IDataErrorInfo.this[string columnName]
 {
     get { return(ErrorsContainer.GetErrors(columnName).FirstOrDefault()); }
 }
Пример #4
0
 /// <summary>
 /// Gets the validation errors for a specified property or for the entire object.
 /// </summary>
 /// <param name="propertyName">The name of the property to retrieve validation errors for, or null or <see cref="F:System.String.Empty"/> to retrieve errors for the entire object.</param>
 /// <returns>
 /// The validation errors for the property or object.
 /// </returns>
 IEnumerable INotifyDataErrorInfo.GetErrors(string propertyName)
 {
     return(ErrorsContainer.GetErrors(propertyName));
 }