FormatErrorMessage() public method

Applies formatting to a specified error message.
public FormatErrorMessage ( string name ) : string
name string The name of the field that caused the validation failure.
return string
        public void AddValidation_WithMinAndMaxLength_AddsAttributes()
        {
            // Arrange
            var provider = TestModelMetadataProvider.CreateDefaultProvider();
            var metadata = provider.GetMetadataForProperty(typeof(string), "Length");

            var attribute = new StringLengthAttribute(10)
            {
                MinimumLength = 3
            };
            var adapter = new StringLengthAttributeAdapter(attribute, stringLocalizer: null);

            var expectedMessage = attribute.FormatErrorMessage("Length");

            var actionContext = new ActionContext();
            var context       = new ClientModelValidationContext(actionContext, metadata, provider, new Dictionary <string, string>());

            // Act
            adapter.AddValidation(context);

            // Assert
            Assert.Collection(
                context.Attributes,
                kvp => { Assert.Equal("data-val", kvp.Key); Assert.Equal("true", kvp.Value); },
                kvp => { Assert.Equal("data-val-length", kvp.Key); Assert.Equal(expectedMessage, kvp.Value); },
                kvp => { Assert.Equal("data-val-length-max", kvp.Key); Assert.Equal("10", kvp.Value); },
                kvp => { Assert.Equal("data-val-length-min", kvp.Key); Assert.Equal("3", kvp.Value); });
        }
        public void Entity_EndEditValidatesPropertyValues()
        {
            // Start with an entity that has required properties satisfied, but has
            // an invalid property value (for StateName)
            Cities.City city = new Cities.City("This is an invalid state name")
            {
                Name = "Redmond"
            };
            IEditableObject editableCity = (IEditableObject)city;

            StringLengthAttribute template = new StringLengthAttribute(2);
            string expectedMember          = "StateName";
            string expectedError           = template.FormatErrorMessage(expectedMember);

            // Begin the edit transaction
            editableCity.BeginEdit();

#if SILVERLIGHT
            // End the edit transaction, which performs property and entity-level validation
            editableCity.EndEdit();
            Assert.AreEqual <int>(1, city.ValidationErrors.Count, "After EndEdit");
            Assert.AreEqual <int>(1, city.ValidationErrors.Single().MemberNames.Count(), "MemberNames count after EndEdit");
            Assert.AreEqual <string>(expectedMember, city.ValidationErrors.Single().MemberNames.Single(), "Member name after EndEdit");
            Assert.AreEqual <string>(expectedError, city.ValidationErrors.Single().ErrorMessage, "ErrorMessage after EndEdit");
#else
            ExceptionHelper.ExpectException <ValidationException>(delegate
            {
                ((IEditableObject)city).EndEdit();
            }, expectedError);
#endif
        }
Beispiel #3
0
        public void GetClientValidationRules_WithMinAndMaxLength_ReturnsValidationParameters()
        {
            // Arrange
            var provider  = TestModelMetadataProvider.CreateDefaultProvider();
            var metadata  = provider.GetMetadataForProperty(typeof(string), "Length");
            var attribute = new StringLengthAttribute(10)
            {
                MinimumLength = 3
            };
            var adapter           = new StringLengthAttributeAdapter(attribute, stringLocalizer: null);
            var serviceCollection = new ServiceCollection();
            var requestServices   = serviceCollection.BuildServiceProvider();
            var context           = new ClientModelValidationContext(metadata, provider, requestServices);

            // Act
            var rules = adapter.GetClientValidationRules(context);

            // Assert
            var rule = Assert.Single(rules);

            Assert.Equal("length", rule.ValidationType);
            Assert.Equal(2, rule.ValidationParameters.Count);
            Assert.Equal(3, rule.ValidationParameters["min"]);
            Assert.Equal(10, rule.ValidationParameters["max"]);
            Assert.Equal(attribute.FormatErrorMessage("Length"), rule.ErrorMessage);
        }
        public void FormatErrorMessage_MinimumLength_CustomError()
        {
            var attrib = new StringLengthAttribute(3)
            {
                MinimumLength = 1, ErrorMessage = "Foo {0} Bar {1} Baz {2}"
            };

            Assert.AreEqual("Foo SOME_NAME Bar 3 Baz 1", attrib.FormatErrorMessage("SOME_NAME"));
        }
        public static string GetStringLengthErrorMessage(int?minimumLength, int maximumLength, string field)
        {
            var attr = new StringLengthAttribute(maximumLength);

            if (minimumLength != null)
            {
                attr.MinimumLength = (int)minimumLength;
            }

            return(attr.FormatErrorMessage(field));
        }
        /// <summary>
        /// Checks the length of the string to verify whether or not it falls within the permissible limits.
        /// </summary>
        /// <param name="variable">The variable in context.</param>
        /// <param name="getVariableName">The name of the variable that should be populated in the error context.</param>
        /// <param name="minimumLength">The minimum length of the variable.</param>
        /// <param name="maximumLength">The maximum length of the variable.</param>
        /// <param name="actionContext">Current action context.</param>
        /// <param name="modelState">Current model object.</param>
        /// <returns>The status of the operation.</returns>
        public static bool StringLength(string variable, Expression <Func <string, string> > getVariableName, int minimumLength, int maximumLength, HttpActionContext actionContext, ModelStateDictionary modelState)
        {
            var variableName = ((MemberExpression)getVariableName.Body).Member.Name;
            var attr         = new StringLengthAttribute(maximumLength)
            {
                MinimumLength = minimumLength
            };

            if (!attr.IsValid(variable))
            {
                modelState.AddModelError(attr.ToString(), attr.FormatErrorMessage(variableName));

                AddErrorToResponse(actionContext, modelState);
                return(false);
            }

            return(true);
        }
Beispiel #7
0
        public void GetClientValidationRules_WithMaxLength_ReturnsValidationParameters()
        {
            // Arrange
            var provider  = new DataAnnotationsModelMetadataProvider();
            var metadata  = provider.GetMetadataForProperty(() => null, typeof(string), "Length");
            var attribute = new StringLengthAttribute(8);
            var adapter   = new StringLengthAttributeAdapter(attribute);
            var context   = new ClientModelValidationContext(metadata, provider);

            // Act
            var rules = adapter.GetClientValidationRules(context);

            // Assert
            var rule = Assert.Single(rules);

            Assert.Equal("length", rule.ValidationType);
            Assert.Equal(1, rule.ValidationParameters.Count);
            Assert.Equal(8, rule.ValidationParameters["max"]);
            Assert.Equal(attribute.FormatErrorMessage("Length"), rule.ErrorMessage);
        }
 public void FormatErrorMessage_MinimumLength_CustomError() {
     var attrib = new StringLengthAttribute(3) { MinimumLength = 1, ErrorMessage = "Foo {0} Bar {1} Baz {2}" };
     Assert.AreEqual("Foo SOME_NAME Bar 3 Baz 1", attrib.FormatErrorMessage("SOME_NAME"));
 }
 public void FormatErrorMessage_MinimumLength() {
     var attrib = new StringLengthAttribute(3) { MinimumLength = 1 };
     Assert.AreEqual(String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.StringLengthAttribute_ValidationErrorIncludingMinimum, "SOME_NAME", 3, 1), attrib.FormatErrorMessage("SOME_NAME"));
 }
 public void FormatErrorMessage() {
     var attrib = new StringLengthAttribute(3);
     Assert.AreEqual(String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.StringLengthAttribute_ValidationError, "SOME_NAME", 3), attrib.FormatErrorMessage("SOME_NAME"));
 }
        public void FormatErrorMessage_MinimumLength()
        {
            var attrib = new StringLengthAttribute(3)
            {
                MinimumLength = 1
            };

            Assert.AreEqual(String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.StringLengthAttribute_ValidationErrorIncludingMinimum, "SOME_NAME", 3, 1), attrib.FormatErrorMessage("SOME_NAME"));
        }
        public void FormatErrorMessage()
        {
            var attrib = new StringLengthAttribute(3);

            Assert.AreEqual(String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.StringLengthAttribute_ValidationError, "SOME_NAME", 3), attrib.FormatErrorMessage("SOME_NAME"));
        }
Beispiel #13
0
        protected void ValidateMLData(List <ValidationResult> rv)
        {
            Dictionary <string, int>    counter     = new Dictionary <string, int>();
            Dictionary <string, int>    required    = new Dictionary <string, int>();
            Dictionary <string, string> lengthError = new Dictionary <string, string>();

            if (Entity is IMLData)
            {
                dynamic dEntity = Entity;
                if (dEntity.MLContents != null)
                {
                    foreach (var lan in BaseController.Languages)
                    {
                        MLContent found = null;
                        foreach (var ml in dEntity.MLContents)
                        {
                            if (ml.LanguageCode == lan.LanguageCode)
                            {
                                found = ml;
                            }
                        }

                        var mltype = (dEntity.MLContents.GetType() as Type).GetGenericArguments()[0];
                        var pros   = mltype.GetProperties();
                        foreach (var pro in pros)
                        {
                            if (pro.PropertyType == typeof(string))
                            {
                                if (!counter.ContainsKey(pro.Name))
                                {
                                    counter[pro.Name] = 0;
                                }
                                if (!required.ContainsKey(pro.Name))
                                {
                                    object[] attrs = pro.GetCustomAttributes(typeof(MLRequiredAttribute), false);
                                    if (attrs.Length > 0)
                                    {
                                        MLRequiredAttribute attr = attrs[0] as MLRequiredAttribute;
                                        if (attr.AllLanguageRequired == true)
                                        {
                                            required[pro.Name] = 2;
                                        }
                                        else
                                        {
                                            required[pro.Name] = 1;
                                        }
                                    }
                                    else
                                    {
                                        required[pro.Name] = 0;
                                    }
                                }

                                if (found != null)
                                {
                                    object[] attrs = pro.GetCustomAttributes(typeof(StringLengthAttribute), false);
                                    if (attrs.Length > 0)
                                    {
                                        StringLengthAttribute attr = attrs[0] as StringLengthAttribute;
                                        object val = pro.GetValue(found, null);
                                        if (val is string && val != null && val.ToString().Length > attr.MaximumLength)
                                        {
                                            lengthError[pro.Name] = attr.FormatErrorMessage(null);
                                        }
                                    }
                                }
                                object v = null;
                                if (found != null)
                                {
                                    v = pro.GetValue(found, null);
                                }
                                if (v != null && v.ToString().Trim() != "")
                                {
                                    counter[pro.Name] = counter[pro.Name] + 1;
                                }
                            }
                        }
                    }
                }
            }

            foreach (var item in lengthError)
            {
                rv.Add(new ValidationResult(item.Value, new[] { "Entity.MLContents" + item.Key }));
            }

            foreach (var item in required)
            {
                if (item.Value == 1 && counter[item.Key] == 0)
                {
                    rv.Add(new ValidationResult(Resources.Language.多语言_一种, new[] { "Entity.MLContents" + item.Key }));
                }
                else
                {
                    if (counter[item.Key] < item.Value)
                    {
                        rv.Add(new ValidationResult(Resources.Language.多语言_全部, new[] { "Entity.MLContents" + item.Key }));
                    }
                }
            }
        }
        private void LoadAttributes(ModelMetadata metadata)
        {
            //TO-DO: Refazer os métodos para tornar-los mais dinâmicos...

            if (metadata != null)
            {
                MetadataAttribute commonAttribute = new MetadataAttribute()
                {
                    AttributeName = "Common" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DisplayName", metadata.DisplayName },
                        { "ShortDisplayName", metadata.ShortDisplayName },
                        { "IsRequired", metadata.IsRequired },
                        { "IsReadOnly", metadata.IsReadOnly },
                        { "IsNullableValueType", metadata.IsNullableValueType },
                        { "Description", metadata.Description },
                        { "Watermark", metadata.Watermark },
                        { "ShowForDisplay", metadata.ShowForDisplay },
                        { "ShowForEdit", metadata.ShowForEdit },

                        { "DataTypeName", metadata.DataTypeName },
                        { "IsComplexType", metadata.IsComplexType },
                        { "EditFormatString", metadata.EditFormatString },
                        { "HideSurroundingHtml", metadata.HideSurroundingHtml },
                        { "HtmlEncode", metadata.HtmlEncode },
                        { "ConvertEmptyStringToNull", metadata.ConvertEmptyStringToNull },
                        { "NullDisplayText", metadata.NullDisplayText },
                        { "SimpleDisplayText", metadata.SimpleDisplayText },
                        { "TemplateHint", metadata.TemplateHint },
                        { "DisplayFormatString", metadata.DisplayFormatString },
                    }
                };
                metadataAttributes.Add(commonAttribute);
            }

            HtmlAttributesAttribute htmlAttributesAttribute = GetModelMetadataAttributes(metadata).OfType <HtmlAttributesAttribute>().FirstOrDefault();

            if (htmlAttributesAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "HtmlAttributes" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "ID", htmlAttributesAttribute.ID },
                        { "Name", htmlAttributesAttribute.Name },
                        { "Class", htmlAttributesAttribute.Class },
                        { "Style", htmlAttributesAttribute.Style },
                        { "Width", htmlAttributesAttribute.Width },
                        { "Height", htmlAttributesAttribute.Height },
                        { "Placeholder", htmlAttributesAttribute.Placeholder },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            DataTypeAttribute dataTypeAttribute = GetModelMetadataAttributes(metadata).OfType <DataTypeAttribute>().FirstOrDefault();

            if (dataTypeAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "DataType" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DataType", dataTypeAttribute.DataType },
                        { "ErrorMessage", dataTypeAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", dataTypeAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", dataTypeAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            DataTypeFieldAttribute dataTypeFieldAttribute = GetModelMetadataAttributes(metadata).OfType <DataTypeFieldAttribute>().FirstOrDefault();

            if (dataTypeFieldAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "DataTypeField" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DataType", dataTypeFieldAttribute.DataType },
                        { "ErrorMessage", dataTypeFieldAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", dataTypeFieldAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", dataTypeFieldAttribute.RequiresValidationContext },
                        { "Cols", dataTypeFieldAttribute.Cols },
                        { "Rows", dataTypeFieldAttribute.Rows },
                        { "Wrap", (dataTypeFieldAttribute.HardWrap ? "hard" : null) },
                        { "MinLength", dataTypeFieldAttribute.MinLength },
                        { "MaxLength", dataTypeFieldAttribute.MaxLength },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            RegularExpressionAttribute regularExpressionAttribute = GetModelMetadataAttributes(metadata).OfType <RegularExpressionAttribute>().FirstOrDefault();

            if (regularExpressionAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "RegularExpression" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Pattern", regularExpressionAttribute.Pattern },
                        { "ErrorMessage", regularExpressionAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", regularExpressionAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", regularExpressionAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            StringLengthAttribute stringLengthAttribute = GetModelMetadataAttributes(metadata).OfType <StringLengthAttribute>().FirstOrDefault();

            if (stringLengthAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "StringLength" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "MinimumLength", stringLengthAttribute.MinimumLength },
                        { "MaximumLength", stringLengthAttribute.MaximumLength },
                        { "ErrorMessage", stringLengthAttribute.ErrorMessage },
                        { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) },
                        { "ErrorMessageResourceName", stringLengthAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", stringLengthAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            MinLengthAttribute minLengthAttribute = GetModelMetadataAttributes(metadata).OfType <MinLengthAttribute>().FirstOrDefault();

            if (minLengthAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "MinLength" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Length", minLengthAttribute.Length },
                        { "TypeId", minLengthAttribute.TypeId },
                        { "ErrorMessage", minLengthAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", minLengthAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", minLengthAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            MaxLengthAttribute maxLengthAttribute = GetModelMetadataAttributes(metadata).OfType <MaxLengthAttribute>().FirstOrDefault();

            if (maxLengthAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "MaxLength" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Length", maxLengthAttribute.Length },
                        { "TypeId", maxLengthAttribute.TypeId },
                        { "ErrorMessage", maxLengthAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", maxLengthAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", maxLengthAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            DisplayAttribute displayAttribute = GetModelMetadataAttributes(metadata).OfType <DisplayAttribute>().FirstOrDefault();

            if (displayAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "Display" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "ShortName", displayAttribute.ShortName },
                        { "Name", displayAttribute.Name },
                        { "Prompt", displayAttribute.Prompt },
                        { "GroupName", displayAttribute.GroupName },
                        { "Description", displayAttribute.Description },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            RequiredAttribute requiredAttribute = GetModelMetadataAttributes(metadata).OfType <RequiredAttribute>().FirstOrDefault();

            if (requiredAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "Required" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "IsRequired", true },
                        { "AllowEmptyStrings", requiredAttribute.AllowEmptyStrings },
                        { "ErrorMessage", requiredAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", requiredAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", requiredAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            RangeAttribute rangeAttribute = GetModelMetadataAttributes(metadata).OfType <RangeAttribute>().FirstOrDefault();

            if (rangeAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "Range" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "OperandType", rangeAttribute.OperandType },
                        { "AllowEmptyStrings", rangeAttribute.Minimum },
                        { "Maximum", rangeAttribute.Maximum },
                        { "ErrorMessage", rangeAttribute.ErrorMessage },
                        { "ErrorMessageResourceName", rangeAttribute.ErrorMessageResourceName },
                        { "RequiresValidationContext", rangeAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            DisplayFormatAttribute displayFormatAttribute = GetModelMetadataAttributes(metadata).OfType <DisplayFormatAttribute>().FirstOrDefault();

            if (displayFormatAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "DisplayFormat" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DataFormatString", displayFormatAttribute.DataFormatString },
                        { "ApplyFormatInEditMode", displayFormatAttribute.ApplyFormatInEditMode },
                        { "ConvertEmptyStringToNull", displayFormatAttribute.ConvertEmptyStringToNull },
                        { "HtmlEncode", displayFormatAttribute.HtmlEncode },
                        { "NullDisplayText", displayFormatAttribute.NullDisplayText },
                        { "IsDefault" + "Attribute", displayFormatAttribute.IsDefaultAttribute() },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            CreditCardAttribute creditCardAttribute = GetModelMetadataAttributes(metadata).OfType <CreditCardAttribute>().FirstOrDefault();

            if (creditCardAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "CreditCard" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DataType", creditCardAttribute.DataType },
                        { "CustomDataType", creditCardAttribute.CustomDataType },
                        { "DisplayFormat", creditCardAttribute.DisplayFormat },
                        { "ErrorMessage", creditCardAttribute.ErrorMessage },
                        { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) },
                        { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName },
                        { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType },
                        { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            CustomValidationAttribute customValidationAttribute = GetModelMetadataAttributes(metadata).OfType <CustomValidationAttribute>().FirstOrDefault();

            if (customValidationAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "CustomValidation" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "ValidatorType", customValidationAttribute.ValidatorType },
                        { "Method", customValidationAttribute.Method },
                        { "ErrorMessage", creditCardAttribute.ErrorMessage },
                        { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) },
                        { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName },
                        { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType },
                        { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            EmailAddressAttribute emailAddressAttribute = GetModelMetadataAttributes(metadata).OfType <EmailAddressAttribute>().FirstOrDefault();

            if (emailAddressAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "EmailAddress" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DataType", emailAddressAttribute.DataType },
                        { "CustomDataType", emailAddressAttribute.CustomDataType },
                        { "DisplayFormat", emailAddressAttribute.DisplayFormat },
                        { "ErrorMessage", creditCardAttribute.ErrorMessage },
                        { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) },
                        { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName },
                        { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType },
                        { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            FileExtensionsAttribute fileExtensionsAttribute = GetModelMetadataAttributes(metadata).OfType <FileExtensionsAttribute>().FirstOrDefault();

            if (fileExtensionsAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "FileExtensions" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "DataType", emailAddressAttribute.DataType },
                        { "CustomDataType", emailAddressAttribute.CustomDataType },
                        { "DisplayFormat", emailAddressAttribute.DisplayFormat },
                        { "ErrorMessage", creditCardAttribute.ErrorMessage },
                        { "FormatErrorMessage", stringLengthAttribute.FormatErrorMessage(metadata.PropertyName) },
                        { "ErrorMessageResourceName", creditCardAttribute.ErrorMessageResourceName },
                        { "ErrorMessageResourceType", creditCardAttribute.ErrorMessageResourceType },
                        { "RequiresValidationContext", creditCardAttribute.RequiresValidationContext },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            TimestampAttribute timestampAttribute = GetModelMetadataAttributes(metadata).OfType <TimestampAttribute>().FirstOrDefault();

            if (timestampAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "FileExtensions" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "TypeId", timestampAttribute.TypeId },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            ViewDisabledAttribute viewDisabledAttribute = GetModelMetadataAttributes(metadata).OfType <ViewDisabledAttribute>().FirstOrDefault();

            if (viewDisabledAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "ViewDisabled" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Declared", true },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            TextAreaAttribute textAreaAttribute = GetModelMetadataAttributes(metadata).OfType <TextAreaAttribute>().FirstOrDefault();

            if (textAreaAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "TextArea" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Cols", textAreaAttribute.Cols },
                        { "Rows", textAreaAttribute.Rows },
                        { "Wrap", (textAreaAttribute.HardWrap ? "hard" : null) },
                        { "MinLength", textAreaAttribute.MinLength },
                        { "MaxLength", textAreaAttribute.MaxLength },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            OnlyNumberAttribute onlyNumberAttribute = GetModelMetadataAttributes(metadata).OfType <OnlyNumberAttribute>().FirstOrDefault();

            if (onlyNumberAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "OnlyNumber" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Declared", true },
                        { "ClassDecorator", "onlyNumber" },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            CurrencyAttribute currencyAttribute = GetModelMetadataAttributes(metadata).OfType <CurrencyAttribute>().FirstOrDefault();

            if (currencyAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "Currency" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Declared", true },
                        { "ClassDecorator", "onlyNumber" },
                        { "Pattern", "currency" },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            NoEspecialCharsAttribute noEspecialCharsAttribute = GetModelMetadataAttributes(metadata).OfType <NoEspecialCharsAttribute>().FirstOrDefault();

            if (noEspecialCharsAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "NoEspecialChars" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Declared", true },
                        { "ClassDecorator", "noCaracEsp" },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            ProgressAttribute progressAttribute = GetModelMetadataAttributes(metadata).OfType <ProgressAttribute>().FirstOrDefault();

            if (progressAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "Progress" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "MinValue", progressAttribute.MinValue },
                        { "MaxValue", progressAttribute.MaxValue },
                        { "Step", progressAttribute.Step },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }

            PlaceHolderAttribute placeHolderAttribute = GetModelMetadataAttributes(metadata).OfType <PlaceHolderAttribute>().FirstOrDefault();

            if (placeHolderAttribute != null)
            {
                MetadataAttribute metaAttribute = new MetadataAttribute()
                {
                    AttributeName = "PlaceHolder" + "Attribute",
                    Property      = new Dictionary <string, object>()
                    {
                        { "Declared", true },
                        { "Text", placeHolderAttribute.Text },
                    }
                };
                metadataAttributes.Add(metaAttribute);
            }
        }