public DataAnnotationsModelMetadata(DataAnnotationsModelMetadataProvider provider, Type containerType,
                                     Func<object> modelAccessor, Type modelType, string propertyName,
                                     DisplayColumnAttribute displayColumnAttribute)
     : base(provider, containerType, modelAccessor, modelType, propertyName)
 {
     _displayColumnAttribute = displayColumnAttribute;
 }
 private static void ValidateDisplayColumnAttribute(DisplayColumnAttribute displayColumnAttribute, PropertyInfo displayColumnProperty, Type modelType) {
     if (displayColumnProperty == null) {
         throw new InvalidOperationException(
             String.Format(
                 CultureInfo.CurrentCulture,
                 MvcResources.DataAnnotationsModelMetadataProvider_UnknownProperty,
                 modelType.FullName, displayColumnAttribute.DisplayColumn));
     }
     if (displayColumnProperty.GetGetMethod() == null) {
         throw new InvalidOperationException(
             String.Format(
                 CultureInfo.CurrentCulture,
                 MvcResources.DataAnnotationsModelMetadataProvider_UnreadableProperty,
                 modelType.FullName, displayColumnAttribute.DisplayColumn));
     }
 }
Beispiel #3
0
        public BscModelMetadata(DataAnnotationsModelMetadataProvider provider, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName, DisplayColumnAttribute displayColumnAttribute, IEnumerable<Attribute> attributes)
            : base(provider, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute)
        {
            var descAttr = attributes.OfType<DescriptionAttribute>().SingleOrDefault();
            _description = descAttr != null ? descAttr.Description : "";

            DataSourceAttribute = attributes.OfType<DataSourceAttribute>().SingleOrDefault();

            var enumAttribute = attributes.OfType<EnumDataTypeAttribute>().SingleOrDefault();
            if (enumAttribute != null)
            {
                DataSource = new EnumTypeSelectListDataSource(enumAttribute.EnumType);
            }

            Attributes = attributes;

            var defaultValueAttr = attributes.OfType<DefaultValueAttribute>().SingleOrDefault();

            DefaultValue = defaultValueAttr != null ? defaultValueAttr.Value : this.ModelType.GetDefaultValue();

            this.AdditionalValues["DefaultValue"] = DefaultValue;
        }
 public FieldTemplateMetadata(DataAnnotationsModelMetadataProvider provider, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName, DisplayColumnAttribute displayColumnAttribute, IEnumerable<Attribute> attributes)
     : base(provider, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute)
 {
     this.Attributes = new List<Attribute>(attributes);
 }
 public PropertyValueMetadata(DataAnnotationsModelMetadataProvider provider, Type containerType, Func <object> modelAccessor, Type modelType, String propertyName, System.ComponentModel.DataAnnotations.DisplayColumnAttribute displayColumnAttribute)
     : base(provider, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute)
 {
     //CurrentPropertyValue = (PropertyValue)modelAccessor();
 }
 /// <summary>
 /// Set the metadata of display property.
 /// </summary>
 /// <param name="display">Display attribute.</param>
 protected virtual void SetDisplayColumn(DisplayColumnAttribute display)
 {
     if (display == null)
         throw new ArgumentNullException("display");
     DisplayProperty = GetProperty(display.DisplayColumn);
     if (display.SortColumn != null)
     {
         SortProperty = GetProperty(display.SortColumn);
         SortDescending = display.SortDescending;
     }
 }