Esempio n. 1
0
        /// <summary>
        /// Adds the validate attribute.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        public void AddValidateAttribute(ValidateAttribute attribute)
        {
            Ensure.IsNotNull(attribute, "PropertyValidator.AddValidateAttribute-attribute");
            if (attribute.FormValidationOrder < this.FormValidationOrder)
            {
                this.FormValidationOrder = attribute.FormValidationOrder;
            }

            this.validateAttributes.Add(attribute);
        }
        /// <summary>
        /// Tries the resolve error message by id.
        /// </summary>
        /// <param name="validateAttribute">The validate attribute.</param>
        /// <param name="args">The args.</param>
        /// <returns>The validation message</returns>
        internal static string TryResolveErrorMessageById(ValidateAttribute validateAttribute, ValidationArgs args)
        {
            string message = string.Empty;
            if (ResolveErrorMessageById != null)
            {
                message = ResolveErrorMessageById(validateAttribute, args);
            }

            if (string.IsNullOrWhiteSpace(message))
            {
                string key = string.Concat(validateAttribute.MessageId, '|', args.Instance.ContextLanguage);
                if (!Cache.TryGetValue(key, out message))
                {
                    message = args.PropertyName;
                }
            }

            return message;
        }