GetBusinessRuleErrors() публичный Метод

Gets all the business rule errors.
public GetBusinessRuleErrors ( ) : List
Результат List
Пример #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);
                    }
                }
            }
        }
Пример #2
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 ReturnsRightValidationsForEmptyContextWithTag()
            {
                var context = new ValidationContext();

                var businessRuleValidations = context.GetBusinessRuleErrors("tag");
                Assert.AreEqual(0, businessRuleValidations.Count);
            }