Beispiel #1
0
        private static JqGridColumnModel CreateJqGridColumnModel(ModelMetadata columnMetadata)
        {
            JqGridColumnModel columnModel = new JqGridColumnModel(columnMetadata.PropertyName);

            TimestampAttribute             timeStampAttribute             = null;
            JqGridColumnLayoutAttribute    jqGridColumnLayoutAttribute    = null;
            JqGridColumnSortableAttribute  jqGridColumnSortableAttribute  = null;
            JqGridColumnFormatterAttribute jqGridColumnFormatterAttribute = null;
            JqGridColumnSummaryAttribute   jqGridColumnSummaryAttribute   = null;

            foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true))
            {
                timeStampAttribute             = (customAttribute as TimestampAttribute) ?? timeStampAttribute;
                jqGridColumnLayoutAttribute    = (customAttribute as JqGridColumnLayoutAttribute) ?? jqGridColumnLayoutAttribute;
                jqGridColumnSortableAttribute  = (customAttribute as JqGridColumnSortableAttribute) ?? jqGridColumnSortableAttribute;
                jqGridColumnFormatterAttribute = (customAttribute as JqGridColumnFormatterAttribute) ?? jqGridColumnFormatterAttribute;
                jqGridColumnSummaryAttribute   = (customAttribute as JqGridColumnSummaryAttribute) ?? jqGridColumnSummaryAttribute;
            }

            if (timeStampAttribute != null)
            {
            }
            else
            {
                columnModel = SetLayoutOptions(columnModel, jqGridColumnLayoutAttribute);
                columnModel = SetSortOptions(columnModel, jqGridColumnSortableAttribute);
                columnModel = SetFormatterOptions(columnModel, jqGridColumnFormatterAttribute);
                columnModel = SetSummaryOptions(columnModel, jqGridColumnSummaryAttribute);
            }

            return(columnModel);
        }
        public void OverwrittenTimestampMetadata()
        {
            // Create the DSD to register type descriptors
            DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TMPT_DomainService));

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(TMPT_MockEntity2));

            PropertyDescriptor descriptor = properties["Timestamp"];

            Assert.IsNotNull(descriptor,
                             "There should be a property descriptor for Timestamp.");
            Assert.AreEqual(typeof(DateTime), descriptor.PropertyType,
                            "The Timestamp type should be a DateTime.");

            TimestampAttribute timestampAttribute = (TimestampAttribute)descriptor.Attributes[typeof(TimestampAttribute)];

            Assert.IsNotNull(timestampAttribute,
                             "The Timestamp should have a TimestampAttribute.");

            EditableAttribute editableAttribute = (EditableAttribute)descriptor.Attributes[typeof(EditableAttribute)];

            Assert.IsNotNull(editableAttribute,
                             "The Timestamp should have an EditableAttribute.");
            Assert.IsTrue(editableAttribute.AllowEdit,
                          "The Timestamp should allow editing.");
            Assert.IsTrue(editableAttribute.AllowInitialValue,
                          "The Timestamp should allow an initial value.");

            DisplayAttribute displayAttribute = (DisplayAttribute)descriptor.Attributes[typeof(DisplayAttribute)];

            Assert.IsNotNull(displayAttribute,
                             "The Timestamp should have an DisplayAttribute.");
            Assert.AreEqual("T", displayAttribute.Name,
                            "The Timestamp names should be equal.");
        }
        public void DefaultTimestampMetadata()
        {
            // Create the DSD to register type descriptors
            DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TMPT_DomainService));

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(TMPT_MockEntity1));

            PropertyDescriptor descriptor = properties["Timestamp"];

            Assert.IsNotNull(descriptor,
                             "There should be a property descriptor for Timestamp.");
            Assert.AreEqual(typeof(DateTime), descriptor.PropertyType,
                            "The Timestamp type should be a DateTime.");

            TimestampAttribute timestampAttribute = (TimestampAttribute)descriptor.Attributes[typeof(TimestampAttribute)];

            Assert.IsNotNull(timestampAttribute,
                             "The Timestamp should have a TimestampAttribute.");

            EditableAttribute editableAttribute = (EditableAttribute)descriptor.Attributes[typeof(EditableAttribute)];

            Assert.IsNotNull(editableAttribute,
                             "The Timestamp should have an EditableAttribute.");
            Assert.IsFalse(editableAttribute.AllowEdit,
                           "The Timestamp should not allow editing.");
            Assert.IsFalse(editableAttribute.AllowInitialValue,
                           "The Timestamp should not allow an initial value.");

            DisplayAttribute displayAttribute = (DisplayAttribute)descriptor.Attributes[typeof(DisplayAttribute)];

            Assert.IsNotNull(displayAttribute,
                             "The Timestamp should have an DisplayAttribute.");
            Assert.IsFalse(displayAttribute.AutoGenerateField,
                           "The Timestamp should not be included in autogeneration.");
        }
        private static JqGridColumnModel CreateJqGridColumnModel(ModelMetadata columnMetadata, IUrlHelper urlHelper)
        {
            JqGridColumnModel columnModel = new JqGridColumnModel(columnMetadata.PropertyName);

            TimestampAttribute              timeStampAttribute              = null;
            RangeAttribute                  rangeAttribute                  = null;
            RequiredAttribute               requiredAttribute               = null;
            JqGridColumnLayoutAttribute     jqGridColumnLayoutAttribute     = null;
            JqGridColumnSortableAttribute   jqGridColumnSortableAttribute   = null;
            JqGridColumnFormatterAttribute  jqGridColumnFormatterAttribute  = null;
            JqGridColumnSearchableAttribute jqGridColumnSearchableAttribute = null;
            JqGridColumnEditableAttribute   jqGridColumnEditableAttribute   = null;
            JqGridColumnSummaryAttribute    jqGridColumnSummaryAttribute    = null;
            JqGridColumnMappingAttribute    jqGridColumnMappingAttribute    = null;

            foreach (Attribute customAttribute in columnMetadata.ContainerType.GetProperty(columnMetadata.PropertyName).GetCustomAttributes(true))
            {
                timeStampAttribute              = (customAttribute as TimestampAttribute) ?? timeStampAttribute;
                rangeAttribute                  = (customAttribute as RangeAttribute) ?? rangeAttribute;
                requiredAttribute               = (customAttribute as RequiredAttribute) ?? requiredAttribute;
                jqGridColumnLayoutAttribute     = (customAttribute as JqGridColumnLayoutAttribute) ?? jqGridColumnLayoutAttribute;
                jqGridColumnSortableAttribute   = (customAttribute as JqGridColumnSortableAttribute) ?? jqGridColumnSortableAttribute;
                jqGridColumnFormatterAttribute  = (customAttribute as JqGridColumnFormatterAttribute) ?? jqGridColumnFormatterAttribute;
                jqGridColumnSearchableAttribute = (customAttribute as JqGridColumnSearchableAttribute) ?? jqGridColumnSearchableAttribute;
                jqGridColumnEditableAttribute   = (customAttribute as JqGridColumnEditableAttribute) ?? jqGridColumnEditableAttribute;
                jqGridColumnSummaryAttribute    = (customAttribute as JqGridColumnSummaryAttribute) ?? jqGridColumnSummaryAttribute;
                jqGridColumnMappingAttribute    = (customAttribute as JqGridColumnMappingAttribute) ?? jqGridColumnMappingAttribute;
            }

            if (timeStampAttribute != null)
            {
                columnModel.Editable = true;
                columnModel.Hidden   = true;
            }
            else
            {
                columnModel = SetLayoutOptions(columnModel, jqGridColumnLayoutAttribute);
                columnModel = SetSortOptions(columnModel, jqGridColumnSortableAttribute);
                columnModel = SetFormatterOptions(columnModel, jqGridColumnFormatterAttribute);
                columnModel = SetSearchOptions(columnModel, urlHelper, columnMetadata.ModelType, jqGridColumnSearchableAttribute, rangeAttribute);
                columnModel = SetEditOptions(columnModel, urlHelper, columnMetadata.ModelType, jqGridColumnEditableAttribute, rangeAttribute, requiredAttribute);
                columnModel = SetDatePickerDateFormatFromFormatter(columnModel, jqGridColumnFormatterAttribute);
                columnModel = SetSummaryOptions(columnModel, jqGridColumnSummaryAttribute);
                columnModel = SetMappingOptions(columnModel, jqGridColumnMappingAttribute);
            }

            return(columnModel);
        }
        /// <summary> Write a Timestamp XML Element from attributes in a member. </summary>
        public virtual void WriteTimestamp(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, TimestampAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "timestamp" );
            // Attribute: <name>
            writer.WriteAttributeString("name", attribute.Name==null ? DefaultHelper.Get_Timestamp_Name_DefaultValue(member) : GetAttributeValue(attribute.Name, mappedClass));
            // Attribute: <node>
            if(attribute.Node != null)
            writer.WriteAttributeString("node", GetAttributeValue(attribute.Node, mappedClass));
            // Attribute: <column>
            if(attribute.Column != null)
            writer.WriteAttributeString("column", GetAttributeValue(attribute.Column, mappedClass));
            // Attribute: <access>
            if(attribute.Access != null)
            writer.WriteAttributeString("access", GetAttributeValue(attribute.Access, mappedClass));
            // Attribute: <unsaved-value>
            if(attribute.UnsavedValue != TimestampUnsavedValue.Unspecified)
            writer.WriteAttributeString("unsaved-value", GetXmlEnumValue(typeof(TimestampUnsavedValue), attribute.UnsavedValue));
            // Attribute: <source>
            if(attribute.Source != TimestampSource.Unspecified)
            writer.WriteAttributeString("source", GetXmlEnumValue(typeof(TimestampSource), attribute.Source));
            // Attribute: <generated>
            if(attribute.Generated != VersionGeneration.Unspecified)
            writer.WriteAttributeString("generated", GetXmlEnumValue(typeof(VersionGeneration), attribute.Generated));

            WriteUserDefinedContent(writer, member, null, attribute);

            System.Collections.ArrayList memberAttribs = GetSortedAttributes(member);
            int attribPos; // Find the position of the TimestampAttribute (its <sub-element>s must be after it)
            for(attribPos=0; attribPos<memberAttribs.Count; attribPos++)
                if( memberAttribs[attribPos] is TimestampAttribute
                    && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position )
                    break; // found
            int i = attribPos + 1;

            // Element: <meta>
            for(; i<memberAttribs.Count; i++)
            {
                BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute;
                if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType())
                    || IsNextElement(memberAttrib, attribute, typeof(MetaAttribute)) )
                    break; // next attributes are 'elements' of the same level OR for 'sub-elements'
                else
                {
                    if( memberAttrib is TimestampAttribute )
                        break; // Following attributes are for this Timestamp
                    if( memberAttrib is MetaAttribute )
                        WriteMeta(writer, member, memberAttrib as MetaAttribute, attribute, mappedClass);
                }
            }
            WriteUserDefinedContent(writer, member, typeof(MetaAttribute), attribute);

            writer.WriteEndElement();
        }
Beispiel #6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TimestampModel"/> class.
		/// </summary>
		/// <param name="prop">The prop.</param>
		/// <param name="att">The att.</param>
		public TimestampModel(PropertyInfo prop, TimestampAttribute att)
		{
			this.prop = prop;
			this.att = att;
		}
Beispiel #7
0
        private void ProcessProperties(Type type, ActiveRecordModel model)
        {
            // Check persistent properties of the base class as well
            if (ShouldCheckBase(type))
            {
                ProcessProperties(type.BaseType, model);
            }

            PropertyInfo[] props = type.GetProperties(DefaultBindingFlags);

            foreach (PropertyInfo prop in props)
            {
                bool              isArProperty = false;
                AnyModel          anyModel;
                HasManyToAnyModel hasManyToAnyModel;

                if (extension != null)
                {
                    extension.ProcessProperty(prop, model);
                }

                object[] valAtts = prop.GetCustomAttributes(typeof(AbstractValidationAttribute), true);

                foreach (AbstractValidationAttribute valAtt in valAtts)
                {
                    IValidator validator = valAtt.Build();
                    validator.Initialize(validatorRegistry, prop);

                    model.Validators.Add(validator);
                }

                foreach (object attribute in prop.GetCustomAttributes(false))
                {
                    if (attribute is PrimaryKeyAttribute)
                    {
                        PrimaryKeyAttribute propAtt = attribute as PrimaryKeyAttribute;
                        isArProperty = true;

                        // Joined Subclasses must not have PrimaryKey
                        if (HasJoinedBase(type))
                        {
                            throw new ActiveRecordException("You can't specify a PrimaryKeyAttribute in a joined subclass. " +
                                                            "Check type " + model.Type.FullName);
                        }

                        if (prop.PropertyType.IsDefined(typeof(CompositeKeyAttribute), true))
                        {
                            object[] att = prop.PropertyType.GetCustomAttributes(typeof(CompositeKeyAttribute), true);

                            CompositeKeyAttribute cAtt = att[0] as CompositeKeyAttribute;

                            model.CompositeKey = new CompositeKeyModel(prop, cAtt);
                        }
                        else
                        {
                            if (!propAtt.IsOverride && model.PrimaryKey != null)
                            {
                                throw new ActiveRecordException("You can't specify more than one PrimaryKeyAttribute in a " +
                                                                "class. Check type " + model.Type.FullName);
                            }

                            model.PrimaryKey = new PrimaryKeyModel(prop, propAtt);
                        }
                    }
                    else if (attribute is CompositeKeyAttribute)
                    {
                        CompositeKeyAttribute propAtt = attribute as CompositeKeyAttribute;
                        isArProperty = true;

                        model.CompositeKey = new CompositeKeyModel(prop, propAtt);
                    }
                    else if (attribute is AnyAttribute)
                    {
                        AnyAttribute anyAtt = attribute as AnyAttribute;
                        isArProperty = true;
                        anyModel     = new AnyModel(prop, anyAtt);
                        model.Anys.Add(anyModel);

                        CollectMetaValues(anyModel.MetaValues, prop);
                    }
                    else if (attribute is PropertyAttribute)
                    {
                        PropertyAttribute propAtt = attribute as PropertyAttribute;
                        isArProperty = true;

                        // If this property overrides a base class property remove the old one
                        if (propAtt.IsOverride)
                        {
                            for (int index = 0; index < model.Properties.Count; ++index)
                            {
                                PropertyModel oldModel = (PropertyModel)model.Properties[index];

                                if (oldModel.Property.Name == prop.Name)
                                {
                                    model.Properties.RemoveAt(index);
                                    break;
                                }
                            }
                        }

                        PropertyModel propModel = new PropertyModel(prop, propAtt);
                        model.Properties.Add(propModel);
                        model.PropertyDictionary[prop.Name] = propModel;
                    }
                    else if (attribute is NestedAttribute)
                    {
                        NestedAttribute propAtt = attribute as NestedAttribute;
                        isArProperty = true;

                        ActiveRecordModel nestedModel = new ActiveRecordModel(prop.PropertyType);

                        nestedModel.IsNestedType = true;

                        Type nestedType = propAtt.MapType ?? prop.PropertyType;
                        nestedModel.IsNestedCompositeType = model.IsNestedCompositeType;
                        ProcessProperties(nestedType, nestedModel);
                        ProcessFields(nestedType, nestedModel);

                        NestedModel nested = new NestedModel(prop, propAtt, nestedModel);
                        nestedModel.ParentNested = nested;

                        model.Components.Add(nested);
                    }
                    else if (attribute is NestedParentReferenceAttribute)
                    {
                        NestedParentReferenceAttribute nestedParentAtt = attribute as NestedParentReferenceAttribute;
                        isArProperty = true;

                        model.ComponentParent.Add(new NestedParentReferenceModel(prop, nestedParentAtt));
                    }
                    else if (attribute is JoinedKeyAttribute)
                    {
                        JoinedKeyAttribute propAtt = attribute as JoinedKeyAttribute;
                        isArProperty = true;

                        if (model.Key != null)
                        {
                            throw new ActiveRecordException("You can't specify more than one JoinedKeyAttribute. " +
                                                            "Check type " + model.Type.FullName);
                        }

                        model.Key = new KeyModel(prop, propAtt);
                    }
                    else if (attribute is VersionAttribute)
                    {
                        VersionAttribute propAtt = attribute as VersionAttribute;
                        isArProperty = true;

                        if (model.Version != null)
                        {
                            throw new ActiveRecordException("You can't specify more than one VersionAttribute. " +
                                                            "Check type " + model.Type.FullName);
                        }

                        model.Version = new VersionModel(prop, propAtt);
                    }
                    else if (attribute is TimestampAttribute)
                    {
                        TimestampAttribute propAtt = attribute as TimestampAttribute;
                        isArProperty = true;

                        if (model.Timestamp != null)
                        {
                            throw new ActiveRecordException("You can't specify more than one TimestampAttribute. " +
                                                            "Check type " + model.Type.FullName);
                        }

                        model.Timestamp = new TimestampModel(prop, propAtt);
                    }
                    // Relations
                    else if (attribute is OneToOneAttribute)
                    {
                        OneToOneAttribute propAtt = attribute as OneToOneAttribute;
                        isArProperty = true;

                        model.OneToOnes.Add(new OneToOneModel(prop, propAtt));
                    }
                    else if (attribute is BelongsToAttribute)
                    {
                        BelongsToAttribute propAtt = attribute as BelongsToAttribute;
                        isArProperty = true;

                        BelongsToModel btModel = new BelongsToModel(prop, propAtt);
                        model.BelongsTo.Add(btModel);
                        model.BelongsToDictionary[prop.Name] = btModel;

                        if (extension != null)
                        {
                            extension.ProcessBelongsTo(prop, btModel, model);
                        }
                    }
                    // The ordering is important here, HasManyToAny must comes before HasMany!
                    else if (attribute is HasManyToAnyAttribute)
                    {
                        HasManyToAnyAttribute propAtt = attribute as HasManyToAnyAttribute;
                        isArProperty = true;

                        hasManyToAnyModel = new HasManyToAnyModel(prop, propAtt);
                        model.HasManyToAny.Add(hasManyToAnyModel);
                        model.HasManyToAnyDictionary[prop.Name] = hasManyToAnyModel;

                        CollectMetaValues(hasManyToAnyModel.MetaValues, prop);

                        if (extension != null)
                        {
                            extension.ProcessHasManyToAny(prop, hasManyToAnyModel, model);
                        }
                    }
                    else if (attribute is HasManyAttribute)
                    {
                        HasManyAttribute propAtt = attribute as HasManyAttribute;
                        isArProperty = true;

                        HasManyModel hasManyModel = new HasManyModel(prop, propAtt, model);
                        if (propAtt.DependentObjects)
                        {
                            ActiveRecordModel dependentObjectModel = new ActiveRecordModel(propAtt.MapType);
                            dependentObjectModel.IsNestedType          = true;
                            dependentObjectModel.IsNestedCompositeType = true;
                            ProcessProperties(propAtt.MapType, dependentObjectModel);

                            hasManyModel.DependentObjectModel = new DependentObjectModel(prop, propAtt, dependentObjectModel);
                        }
                        model.HasMany.Add(hasManyModel);
                        model.HasManyDictionary[prop.Name] = hasManyModel;

                        if (extension != null)
                        {
                            extension.ProcessHasMany(prop, hasManyModel, model);
                        }
                    }
                    else if (attribute is HasAndBelongsToManyAttribute)
                    {
                        HasAndBelongsToManyAttribute propAtt = attribute as HasAndBelongsToManyAttribute;
                        isArProperty = true;

                        HasAndBelongsToManyModel habtManyModel = new HasAndBelongsToManyModel(prop, propAtt);
                        model.HasAndBelongsToMany.Add(habtManyModel);
                        model.HasAndBelongsToManyDictionary[prop.Name] = habtManyModel;

                        if (extension != null)
                        {
                            extension.ProcessHasAndBelongsToMany(prop, habtManyModel, model);
                        }
                    }
                    else if (attribute is Any.MetaValueAttribute)
                    {
                        if (prop.GetCustomAttributes(typeof(HasManyToAnyAttribute), false).Length == 0 &&
                            prop.GetCustomAttributes(typeof(AnyAttribute), false).Length == 0
                            )
                        {
                            throw new ActiveRecordException(
                                      "You can't specify an Any.MetaValue without specifying the Any or HasManyToAny attribute. " +
                                      "Check type " + prop.DeclaringType.FullName);
                        }
                    }
                    else if (attribute is CompositeUserTypeAttribute)
                    {
                        CompositeUserTypeAttribute propAtt = attribute as CompositeUserTypeAttribute;
                        isArProperty = true;

                        model.CompositeUserType.Add(new CompositeUserTypeModel(prop, prop.PropertyType, propAtt));
                    }

                    if (attribute is CollectionIDAttribute)
                    {
                        CollectionIDAttribute propAtt = attribute as CollectionIDAttribute;

                        model.CollectionIDs.Add(new CollectionIDModel(prop, propAtt));
                    }
                    if (attribute is HiloAttribute)
                    {
                        HiloAttribute propAtt = attribute as HiloAttribute;

                        model.Hilos.Add(new HiloModel(prop, propAtt));
                    }
                }

                if (!isArProperty)
                {
                    model.NotMappedProperties.Add(prop);
                }
            }
        }
        internal JqGridColumnModel(ModelMetadata propertyMetadata)
            : this(propertyMetadata.PropertyName)
        {
            IEnumerable <object> customAttributes = propertyMetadata.ContainerType.GetProperty(propertyMetadata.PropertyName).GetCustomAttributes(true).AsEnumerable();

            TimestampAttribute timeStampAttribute = customAttributes.OfType <TimestampAttribute>().FirstOrDefault();

            if (timeStampAttribute != null)
            {
                Editable = true;
                Hidden   = true;
            }
            else
            {
                RangeAttribute rangeAttribute = customAttributes.OfType <RangeAttribute>().FirstOrDefault();

                Alignment      = propertyMetadata.GetColumnAlignment();
                AutoSize       = propertyMetadata.GetColumnAutoSize();
                CellAttributes = propertyMetadata.GetColumnCellAttributes();
                Classes        = propertyMetadata.GetColumnClasses();
                DateFormat     = propertyMetadata.GetColumnDateFormat();
                Fixed          = propertyMetadata.GetColumnFixed();
                Frozen         = propertyMetadata.GetColumnFrozen();
                Key            = propertyMetadata.GetColumnKey();
                Resizable      = propertyMetadata.GetColumnResizable();
                Title          = propertyMetadata.GetColumnTitle();
                Width          = propertyMetadata.GetColumnWidth();
                Viewable       = propertyMetadata.GetColumnViewable();
                Tooltip        = propertyMetadata.GetColumnTooltip();

                Editable    = propertyMetadata.GetColumnEditable();
                EditOptions = propertyMetadata.GetColumnEditOptions();
                if (EditOptions != null)
                {
                    StringLengthAttribute stringLengthAttribute = customAttributes.OfType <StringLengthAttribute>().FirstOrDefault();
                    if (stringLengthAttribute != null)
                    {
                        if (EditOptions.HtmlAttributes == null)
                        {
                            EditOptions.HtmlAttributes = new Dictionary <string, object>();
                        }

                        if (EditOptions.HtmlAttributes.ContainsKey("maxlength"))
                        {
                            EditOptions.HtmlAttributes["maxlength"] = stringLengthAttribute.MaximumLength;
                        }
                        else
                        {
                            EditOptions.HtmlAttributes.Add("maxlength", stringLengthAttribute.MaximumLength);
                        }
                    }
                }
                EditRules = propertyMetadata.GetColumnEditRules();
                if (EditRules != null)
                {
                    RequiredAttribute requiredAttribute = customAttributes.OfType <RequiredAttribute>().FirstOrDefault();
                    if (requiredAttribute != null)
                    {
                        EditRules.Required = true;
                    }

                    if (rangeAttribute != null)
                    {
                        EditRules.MaxValue = Convert.ToDouble(rangeAttribute.Maximum);
                        EditRules.MinValue = Convert.ToDouble(rangeAttribute.Minimum);
                    }
                }
                EditType      = propertyMetadata.GetColumnEditType();
                ExportOptions = propertyMetadata.GetColumnExportOptions();

                Formatter        = propertyMetadata.GetColumnFormatter();
                FormatterOptions = propertyMetadata.GetColumnFormatterOptions();
                UnFormatter      = propertyMetadata.GetColumnUnFormatter();

                FormOptions = propertyMetadata.GetColumnFormOptions();

                LabelOptions = propertyMetadata.GetColumnLabelOptions();

                Searchable    = propertyMetadata.GetColumnSearchable();
                SearchOptions = propertyMetadata.GetColumnSearchOptions();
                SearchRules   = propertyMetadata.GetColumnSearchRules();
                if (SearchRules != null && rangeAttribute != null)
                {
                    SearchRules.MaxValue = Convert.ToDouble(rangeAttribute.Maximum);
                    SearchRules.MinValue = Convert.ToDouble(rangeAttribute.Minimum);
                }
                SearchType = propertyMetadata.GetColumnSearchType();

                InitialSortingOrder = propertyMetadata.GetColumnInitialSortingOrder();
                Sortable            = propertyMetadata.GetColumnSortable();
                SortType            = propertyMetadata.GetColumnSortType();
                SortFunction        = propertyMetadata.GetColumnSortFunction();
                Index = propertyMetadata.GetColumnIndex();

                SummaryType     = propertyMetadata.GetColumnSummaryType();
                SummaryTemplate = propertyMetadata.GetColumnSummaryTemplate();
                SummaryFunction = propertyMetadata.GetColumnSummaryFunction();

                if (!string.IsNullOrWhiteSpace(propertyMetadata.TemplateHint) && propertyMetadata.TemplateHint.Equals("HiddenInput"))
                {
                    Hidden = true;
                }
                else
                {
                    Hidden = false;
                }
                HideInDialog = propertyMetadata.GetColumnHideInDialog();
            }

            JsonMapping = propertyMetadata.GetColumnJsonMapping();
            XmlMapping  = propertyMetadata.GetColumnXmlMapping();
        }
        public static MvcHtmlString TextBoxPadraoFor <TModel, TValue>(this HtmlHelper <TModel> html,
                                                                      Expression <Func <TModel, TValue> > expression, IDictionary <string, object> htmlAttributes)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
            string        id       = ExpressionHelper.GetExpressionText(expression).Split('.').Last().ToLower();
            string        nome     = id;
            //string placeHolder = metadata.Description ?? id;

            bool isRequired = false;

            if (metadata.ContainerType != null)
            {
                isRequired = metadata.ContainerType.GetProperty(metadata.PropertyName)
                             .GetCustomAttributes(typeof(RequiredAttribute), false)
                             .Length == 1;
            }

            TimestampAttribute time = (TimestampAttribute)
                                      Attribute.GetCustomAttribute(
                (expression.Body as MemberExpression ??
                 ((UnaryExpression)expression.Body).Operand as MemberExpression).Member,
                typeof(TimestampAttribute));

            DataTypeAttribute date = (DataTypeAttribute)
                                     Attribute.GetCustomAttribute(
                (expression.Body as MemberExpression ??
                 ((UnaryExpression)expression.Body).Operand as MemberExpression).Member,
                typeof(DataTypeAttribute));

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            string classe      = "";
            string tamanho     = "col-sm-12";
            string group_addon = "";

            if ((expression.ReturnType == typeof(decimal)) || (expression.ReturnType == typeof(decimal?)))
            {
                group_addon = "<span class='input-group-addon'> R$ </span>";
                classe      = "form-control text-right valor"; //input-lg
                var placeHolder = "0,00";
                htmlAttributes.Add("placeholder", placeHolder);
            }
            else if ((date != null) && Equals(date.GetDataTypeName(), "Date"))
            {
                if (!htmlAttributes.ContainsKey("filtrar"))
                {
                    group_addon = "<span class='input-group-addon'><i class='fa fa-calendar'></i></span>";
                }
                classe = "form-control datepicker "; // input-lg
                htmlAttributes.Add("maxlength", "10");
                htmlAttributes.Add("data_dateformat", "dd/mm/yy");
                htmlAttributes.Add("onkeypress", "mascaraDT(this, DATA)");
            }
            else if (time != null)
            {
                group_addon = "<span class='input-group-addon'><i class='fa fa-clock-o'></i></span>";
                classe      = "form-control "; // input-lg
                htmlAttributes.Add("maxlength", "5");
            }
            else
            {
                classe = classe + "form-control "; // input-lg
            }

            htmlAttributes.Add("Name", nome.ToLower());
            htmlAttributes.Add("id", id);

            if (isRequired == true)
            {
                if (classe == "")
                {
                    classe = "requerido";
                }
                else
                {
                    classe = classe + " requerido";
                }
            }
            htmlAttributes.Add("class", classe);

            if (htmlAttributes.ContainsKey("tamanho"))
            {
                tamanho += " " + htmlAttributes["tamanho"];
            }
            htmlAttributes.Add("style", "text-transform:uppercase");


            if ((expression.ReturnType == typeof(decimal)) || (expression.ReturnType == typeof(decimal?)))
            {
                /// refatorar
                StringBuilder str = new StringBuilder();
                str.Append("<div class='input-group'>");
                str.Append(html.TextBoxFor(expression, htmlAttributes));
                str.Append(group_addon);
                str.Append("</div>");

                return(new MvcHtmlString(str.ToString()));
            }
            else if (((date != null) && Equals(date.GetDataTypeName(), "Date")) || (time != null))
            {
                /// refatorar
                StringBuilder str = new StringBuilder();
                str.Append("<div class='input-group'>");
                str.Append(html.TextBoxFor(expression, htmlAttributes));
                str.Append(group_addon);
                str.Append("</div>");

                return(new MvcHtmlString(str.ToString()));
            }
            else
            {
                /// refatorar
                StringBuilder str = new StringBuilder();
                //      str.Append("<div class='col-md-10'>");
                //      str.Append("<div class='row'>");
                //        str.Append("<div class='"+ tamanho+ "'>");
                str.Append(html.TextBoxFor(expression, htmlAttributes));
                //      str.Append("</div>");
                //      str.Append("</div>");
                //       str.Append("</div>");
                return(new MvcHtmlString(str.ToString()));
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine("Your model assembly name:");
            var assemblyName = Console.ReadLine();

            var asm     = Assembly.Load(assemblyName);
            var classes = asm.GetTypes().Where(p => p.IsClass).ToList();

            foreach (var item in classes)
            {
                                // Just grabbing this to get hold of the type name:
                                var type = item.GetType();

                                // Get the PropertyInfo object:
                                var properties = item.GetProperties();

                if (HasEFDataAnnotaion(properties))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Found Data Annotations attributes at {0} ...", item.FullName);
                    foreach (var property in properties)
                    {
                        var attributes = property.GetCustomAttributes(false);

                        // Using reflection.
                        Attribute[] attrs = System.Attribute.GetCustomAttributes(property);

                        // Displaying output.
                        foreach (Attribute attr in attrs)
                        {
                            if (attr is KeyAttribute)
                            {
                                KeyAttribute a = (KeyAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ForeignKeyAttribute)
                            {
                                ForeignKeyAttribute a = (ForeignKeyAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is IndexAttribute)
                            {
                                IndexAttribute a = (IndexAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.GetType().FullName + a.ToString(), property.Name);
                            }

                            if (attr is RequiredAttribute)
                            {
                                RequiredAttribute a = (RequiredAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is TimestampAttribute)
                            {
                                TimestampAttribute a = (TimestampAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ConcurrencyCheckAttribute)
                            {
                                ConcurrencyCheckAttribute a = (ConcurrencyCheckAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is MinLengthAttribute)
                            {
                                MinLengthAttribute a = (MinLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is MaxLengthAttribute)
                            {
                                MaxLengthAttribute a = (MaxLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is StringLengthAttribute)
                            {
                                StringLengthAttribute a = (StringLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is TableAttribute)
                            {
                                TableAttribute a = (TableAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ColumnAttribute)
                            {
                                ColumnAttribute a = (ColumnAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is DatabaseGeneratedAttribute)
                            {
                                DatabaseGeneratedAttribute a = (DatabaseGeneratedAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ComplexTypeAttribute)
                            {
                                ComplexTypeAttribute a = (ComplexTypeAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }
                        }
                    }
                }
            }
        }
 public TimestampModel(PropertyInfo prop, TimestampAttribute att)
 {
     this.prop = prop;
     this.att  = att;
 }
Beispiel #12
0
 private void SetTimestampAttribute(TimestampAttribute a, EntityFieldMetaData m)
 {
     m.IsRowVersion = true;
     SetColumnType("Rowversion", m);
 }
Beispiel #13
0
 private static object[] GetArgs(TimestampAttribute attribute)
 {
     return(new object[] { });
 }
        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);
            }
        }