GetFieldErrors() public method

Gets all the field errors.
public GetFieldErrors ( ) : List
return List
Esempio n. 1
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)
        {
            if (HideValidationResults)
            {
                yield return(null);
            }

            if (string.IsNullOrEmpty(propertyName))
            {
                lock (ValidationContext)
                {
                    foreach (var error in ValidationContext.GetBusinessRuleErrors())
                    {
                        yield return(error.Message);
                    }
                }
            }
            else
            {
                lock (ValidationContext)
                {
                    foreach (var error in ValidationContext.GetFieldErrors(propertyName))
                    {
                        yield return(error.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets an error for a specific column.
        /// </summary>
        /// <param name="columnName">Column name.</param>
        /// <returns>The error or <see cref="string.Empty"/> if no error is available.</returns>
        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                if (string.IsNullOrEmpty(columnName))
                {
                    return(string.Empty);
                }

                if (HideValidationResults)
                {
                    return(string.Empty);
                }

                if (!IsValidated && AutomaticallyValidateOnPropertyChanged)
                {
                    Validate();
                }

                var error = (from fieldError in ValidationContext.GetFieldErrors(columnName)
                             select fieldError.Message).FirstOrDefault();

                return(error ?? string.Empty);
            }
        }
Esempio n. 3
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)
        {
            var elements = new List <string>();

            if (HideValidationResults)
            {
                return(elements);
            }

            if (string.IsNullOrEmpty(propertyName))
            {
                lock (_validationContext)
                {
                    foreach (var error in _validationContext.GetBusinessRuleErrors())
                    {
                        elements.Add(error.Message);
                    }
                }
            }
            else
            {
                lock (_validationContext)
                {
                    foreach (var error in _validationContext.GetFieldErrors(propertyName))
                    {
                        elements.Add(error.Message);
                    }
                }
            }

            return(elements);
        }
            public void ReturnsRightValidationsForEmptyContextWithTagAndPropertyName()
            {
                var context = new ValidationContext();

                var fieldValidations = context.GetFieldErrors("MyProperty");
                Assert.AreEqual(0, fieldValidations.Count);
            }
            public void ReturnsRightValidationsForEmptyContext()
            {
                var context = new ValidationContext();

                var fieldValidations = context.GetFieldErrors();
                Assert.AreEqual(0, fieldValidations.Count);
            }