Catel.Data.ValidationContext.GetFieldValidations C# (CSharp) Method

GetFieldValidations() public method

Gets all the field validations for the specified property name.
The is null or whitespace.
public GetFieldValidations ( string propertyName ) : List
propertyName string Name of the property.
return List
        public List<IFieldValidationResult> GetFieldValidations(string propertyName)
        {
            Argument.IsNotNullOrWhitespace("propertyName", propertyName);

            lock (_fieldValidations)
            {
                var list = (from validation in _fieldValidations
                            where string.Equals(validation.PropertyName, propertyName, StringComparison.OrdinalIgnoreCase)
                            select validation).ToList();

                return list;
            }
        }

Same methods

ValidationContext::GetFieldValidations ( ) : List
ValidationContext::GetFieldValidations ( object tag ) : List
ValidationContext::GetFieldValidations ( string propertyName, object tag ) : List

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Sets the field validation result.
        /// </summary>
        /// <param name="validationResult">The field validation result.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="validationResult"/> is <c>null</c>.</exception>
        protected void SetFieldValidationResult(IFieldValidationResult validationResult)
        {
            Argument.IsNotNull("validationResult", validationResult);

            if (string.IsNullOrEmpty(validationResult.Message))
            {
                return;
            }

            var previousValidations = _internalValidationContext.GetFieldValidations(validationResult.PropertyName);

            // First, check if the same error already exists
            bool alreadyExists = (from previousValidation in previousValidations
                                  where string.Compare(previousValidation.Message, validationResult.Message, StringComparison.Ordinal) == 0
                                  select previousValidation).Any();

            if (alreadyExists)
            {
                return;
            }

            _internalValidationContext.AddFieldValidationResult(validationResult);

            if (!IsValidating)
            {
                switch (validationResult.ValidationResultType)
                {
                case ValidationResultType.Warning:
                    NotifyWarningsChanged(validationResult.PropertyName, true);
                    break;

                case ValidationResultType.Error:
                    NotifyErrorsChanged(validationResult.PropertyName, true);
                    break;
                }
            }
        }
All Usage Examples Of Catel.Data.ValidationContext::GetFieldValidations