Пример #1
0
        protected override void MetadataAssist(ModelMetadata metadata)
        {
            Check.NotNull <ModelMetadata>(metadata, "metadata");
            base.MetadataAssist(metadata);
            System.Collections.Generic.IEnumerable <SelectListItem> listItems  = EnumAttribute.GetListItems(metadata.IsNullableValueType ? System.Nullable.GetUnderlyingType(metadata.ModelType) : metadata.ModelType);
            System.Collections.Generic.Dictionary <string, string>  dictionary = listItems.ToDictionary((SelectListItem item) => item.Value, (SelectListItem item) => item.Text);
            string text = JsonConvert.SerializeObject(dictionary);

            base.ColumnFormatOptions = text;
            base.FilterItems         = text;
        }
Пример #2
0
 public override void OnMetadataCreated(ModelMetadata metadata)
 {
     base.OnMetadataCreated(metadata);
     if (!(metadata.IsNullableValueType ? System.Nullable.GetUnderlyingType(metadata.ModelType) : metadata.ModelType).IsEnum)
     {
         throw new System.InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.EnumAttribute_SettingError_EnumType, new object[]
         {
             Resources.EnumAttribute_DisplayName,
             metadata.PropertyName
         }));
     }
     if (!metadata.IsNullableValueType || base.CustomDefaultValue)
     {
         System.Enum value = System.Enum.ToObject(metadata.ModelType, this.DefaultValue) as System.Enum;
         metadata.AdditionalValues.Add("DefaultValue", value);
     }
     System.Type type = metadata.IsNullableValueType ? System.Nullable.GetUnderlyingType(metadata.ModelType) : metadata.ModelType;
     metadata.AdditionalValues.Add("ListItems", EnumAttribute.GetListItems(type));
     metadata.AdditionalValues.Add("UIType", this.UIType);
 }