/// <summary>
        /// Process display attibute
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="identity"></param>
        public static void Transform([NotNull] DisplayMetadata metadata, ModelMetadataIdentity identity)
        {
            Invariant.IsNotNull(metadata, "metadata");

            if (!DisableNameProcessing && (metadata.DisplayName == null || metadata.DisplayName() == identity.Name))
            {
                metadata.DisplayName = () => identity.Name.SplitUpperCaseToString();
            }
        }
示例#2
0
        /// <summary>
        /// Adds a value to the AdditionalValues collection with a formatted validation message taken from a
        /// ValidationAttribute. Intended to be used as a shortcut for adding validation messages associated with
        /// ValidationAttributes in an implementation of IMetadataAttribute
        /// </summary>
        /// <param name="key">The name of the property (key) to add to the collection.</param>
        /// <param name="value">The value to add to the collection.</param>
        /// <param name="attribute">The attribute from which the validation message will be extracted.</param>
        /// <returns>ModelMetadata instance for method chaining</returns>
        public static DisplayMetadata AddAdditionalValueWithValidationMessage(this DisplayMetadata modelMetaData, string key, object value, ValidationAttribute attribute)
        {
            modelMetaData.AdditionalValues.Add(key, value);
            modelMetaData.AdditionalValues.Add(key + "ValMsg", attribute.FormatErrorMessage(modelMetaData.DisplayName()));

            return(modelMetaData);
        }