public void DisplayAttribute_Resourced_Properties() {
            DisplayAttribute attr = new DisplayAttribute();

            attr.ResourceType = typeof(DisplayAttribute_Resources);

            Assert.IsNull(attr.GetShortName());
            Assert.IsNull(attr.GetName());
            Assert.IsNull(attr.GetPrompt());
            Assert.IsNull(attr.GetDescription());
            Assert.IsNull(attr.GetGroupName());

            attr.ShortName = "Resource1";
            attr.Name = "Resource2";
            attr.Prompt = "Resource3";
            attr.Description = "Resource4";
            attr.GroupName = "Resource5";

            Assert.AreEqual("string1", attr.GetShortName());
            Assert.AreEqual("string2", attr.GetName());
            Assert.AreEqual("string3", attr.GetPrompt());
            Assert.AreEqual("string4", attr.GetDescription());
            Assert.AreEqual("string5", attr.GetGroupName());

            Assert.AreEqual("Resource1", attr.ShortName);
            Assert.AreEqual("Resource2", attr.Name);
            Assert.AreEqual("Resource3", attr.Prompt);
            Assert.AreEqual("Resource4", attr.Description);
            Assert.AreEqual("Resource5", attr.GroupName);
        }
Пример #2
0
        public void DisplayAttribute_Resourced_Properties()
        {
            DisplayAttribute attr = new DisplayAttribute();

            attr.ResourceType = typeof(DisplayAttribute_Resources);

            Assert.IsNull(attr.GetShortName());
            Assert.IsNull(attr.GetName());
            Assert.IsNull(attr.GetPrompt());
            Assert.IsNull(attr.GetDescription());
            Assert.IsNull(attr.GetGroupName());

            attr.ShortName   = "Resource1";
            attr.Name        = "Resource2";
            attr.Prompt      = "Resource3";
            attr.Description = "Resource4";
            attr.GroupName   = "Resource5";

            Assert.AreEqual("string1", attr.GetShortName());
            Assert.AreEqual("string2", attr.GetName());
            Assert.AreEqual("string3", attr.GetPrompt());
            Assert.AreEqual("string4", attr.GetDescription());
            Assert.AreEqual("string5", attr.GetGroupName());

            Assert.AreEqual("Resource1", attr.ShortName);
            Assert.AreEqual("Resource2", attr.Name);
            Assert.AreEqual("Resource3", attr.Prompt);
            Assert.AreEqual("Resource4", attr.Description);
            Assert.AreEqual("Resource5", attr.GroupName);
        }
Пример #3
0
        public void DisplayAttribute_Reflection_Test()
        {
            Type t = typeof(DisplayAttribute_Sample);

            FieldInfo fInfo = t.GetField("stringField");

            Assert.IsNotNull(fInfo);
            Assert.IsNotNull(fInfo.GetCustomAttributes(true).OfType <DisplayAttribute>().SingleOrDefault());

            PropertyInfo pInfo = t.GetProperty("LiteralStringProperty");

            Assert.IsNotNull(pInfo);
            DisplayAttribute attr = pInfo.GetCustomAttributes(true).OfType <DisplayAttribute>().SingleOrDefault();

            Assert.IsNotNull(attr);

            Assert.IsNull(attr.ResourceType);

            Assert.AreEqual("theShortName", attr.ShortName);
            Assert.AreEqual("theName", attr.Name);
            Assert.AreEqual("thePrompt", attr.Prompt);
            Assert.AreEqual("theDescription", attr.Description);
            Assert.AreEqual("theGroupName", attr.GroupName);


            Assert.AreEqual("theShortName", attr.GetShortName());
            Assert.AreEqual("theName", attr.GetName());
            Assert.AreEqual("thePrompt", attr.GetPrompt());
            Assert.AreEqual("theDescription", attr.GetDescription());
            Assert.AreEqual("theGroupName", attr.GetGroupName());


            pInfo = t.GetProperty("ResourcedStringProperty");
            Assert.IsNotNull(pInfo);
            attr = pInfo.GetCustomAttributes(true).OfType <DisplayAttribute>().SingleOrDefault();
            Assert.IsNotNull(attr);

            Assert.AreEqual(typeof(DisplayAttribute_Resources), attr.ResourceType);

            Assert.AreEqual("string1", attr.GetShortName());
            Assert.AreEqual("Resource1", attr.ShortName);

            Assert.AreEqual("string2", attr.GetName());
            Assert.AreEqual("Resource2", attr.Name);

            Assert.AreEqual("string3", attr.GetPrompt());
            Assert.AreEqual("Resource3", attr.Prompt);

            Assert.AreEqual("string4", attr.GetDescription());
            Assert.AreEqual("Resource4", attr.Description);

            Assert.AreEqual("string5", attr.GetGroupName());
            Assert.AreEqual("Resource5", attr.GroupName);
        }
 private void LocalizeDisplayAttribute(ModelMetadata metadata, DisplayAttribute attribute)
 {
     metadata.DisplayName      = Localize(attribute.GetName());
     metadata.ShortDisplayName = Localize(attribute.GetShortName());
     metadata.Description      = Localize(attribute.GetDescription());
     metadata.Watermark        = Localize(attribute.GetPrompt());
 }
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            ModelMetadata res = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);

            FormatAttribute formatAttribute = attributes.OfType <FormatAttribute>().FirstOrDefault();

            if (formatAttribute != null)
            {
                string clientFormat;
                string prefix;
                string postfix;
                formatAttribute.GetClientFormat(out prefix, out postfix, out clientFormat);
                res.AdditionalValues.Add("MVCControlsToolkit.ClientFormatString", clientFormat);
                res.AdditionalValues.Add("MVCControlsToolkit.ClientFormatPrefix", prefix);
                res.AdditionalValues.Add("MVCControlsToolkit.ClientFormatPostfix", postfix);
            }
            DisplayAttribute display = attributes.OfType <DisplayAttribute>().FirstOrDefault();
            string           name    = null;

            if (display != null)
            {
                res.Description      = display.GetDescription();
                res.ShortDisplayName = display.GetShortName();
                res.Watermark        = display.GetPrompt();


                name = display.GetName();
                if (!string.IsNullOrWhiteSpace(name))
                {
                    res.DisplayName = name;
                }
            }
            return(res);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"> </typeparam>
        /// <param name="obj"> </param>
        /// <param name="propertyName"> </param>
        /// <returns> </returns>
        public static string GetPropertyPromptData <T>(this T obj, string propertyName) where T : NotifyPropertyBase
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                return(string.Empty);
            }
            Type         tp    = obj.GetType();
            PropertyInfo pi    = tp.GetProperty(propertyName);
            var          value = pi.GetValue(obj, null);

            object[] Attributes    = pi.GetCustomAttributes(false);
            string   strPromptData = "";

            if (Attributes != null && Attributes.Length > 0)
            {
                foreach (object attribute in Attributes)
                {
                    if (attribute is DisplayAttribute)
                    {
                        try
                        {
                            DisplayAttribute vAttribute = attribute as DisplayAttribute;
                            strPromptData = vAttribute.GetPrompt();
                            break;
                        }
                        catch (Exception ex)
                        {
                            ex.ToString();
                        }
                    }
                }
            }
            return(strPromptData);
        }
Пример #7
0
        public void DisplayAttribute_GetPrompt_Does_Not_Fall_Back()
        {
            DisplayAttribute attr = new DisplayAttribute {
                ShortName = "ShortName", Name = "Name", Description = "Description", GroupName = "GroupName"
            };

            Assert.IsNull(attr.GetPrompt(), "GetPrompt should NOT fall back onto any other values");
        }
Пример #8
0
        /// <summary>
        /// Applies the display attributes.
        /// </summary>
        /// <param name="attr">The attribute.</param>
        /// <param name="pi">The property info.</param>
        private static void ApplyDisplayAttributes(this AttributeModel attr, PropertyInfo pi)
        {
            DisplayAttribute disp = (DisplayAttribute)pi.GetCustomAttribute(typeof(DisplayAttribute));

            attr.DisplayName      = disp == null ? pi.Name : disp.GetName();
            attr.DisplayGroupName = disp?.GetGroupName();
            attr.ShortName        = disp?.GetShortName();
            attr.Prompt           = disp?.GetPrompt();
        }
Пример #9
0
        public string GetPrompt()
        {
            var localizedString = GetLocalizedString(_displayAttribute.Prompt);

            if (localizedString == null)
            {
                localizedString = _displayAttribute.GetPrompt();
            }

            return(localizedString);
        }
Пример #10
0
        public void DisplayAttribute_Literal_Properties()
        {
            DisplayAttribute attr = new DisplayAttribute();

            Assert.IsNull(attr.ResourceType);
            Assert.IsNull(attr.ShortName);
            Assert.IsNull(attr.Name);
            Assert.IsNull(attr.Prompt);
            Assert.IsNull(attr.Description);
            Assert.IsNull(attr.GroupName);

            Assert.IsNull(attr.GetShortName());
            Assert.IsNull(attr.GetName());
            Assert.IsNull(attr.GetPrompt());
            Assert.IsNull(attr.GetDescription());
            Assert.IsNull(attr.GetGroupName());

            attr.ShortName   = "theShortName";
            attr.Name        = "theName";
            attr.Prompt      = "thePrompt";
            attr.Description = "theDescription";
            attr.GroupName   = "theGroupName";

            Assert.AreEqual("theShortName", attr.GetShortName());
            Assert.AreEqual("theName", attr.GetName());
            Assert.AreEqual("thePrompt", attr.GetPrompt());
            Assert.AreEqual("theDescription", attr.GetDescription());
            Assert.AreEqual("theGroupName", attr.GetGroupName());

            attr.ShortName   = String.Empty;
            attr.Name        = String.Empty;
            attr.Prompt      = String.Empty;
            attr.Description = String.Empty;
            attr.GroupName   = String.Empty;

            Assert.AreEqual(String.Empty, attr.GetShortName());
            Assert.AreEqual(String.Empty, attr.GetName());
            Assert.AreEqual(String.Empty, attr.GetPrompt());
            Assert.AreEqual(String.Empty, attr.GetDescription());
            Assert.AreEqual(String.Empty, attr.GetGroupName());
        }
        public void DisplayAttribute_Literal_Properties() {
            DisplayAttribute attr = new DisplayAttribute();

            Assert.IsNull(attr.ResourceType);
            Assert.IsNull(attr.ShortName);
            Assert.IsNull(attr.Name);
            Assert.IsNull(attr.Prompt);
            Assert.IsNull(attr.Description);
            Assert.IsNull(attr.GroupName);

            Assert.IsNull(attr.GetShortName());
            Assert.IsNull(attr.GetName());
            Assert.IsNull(attr.GetPrompt());
            Assert.IsNull(attr.GetDescription());
            Assert.IsNull(attr.GetGroupName());

            attr.ShortName = "theShortName";
            attr.Name = "theName";
            attr.Prompt = "thePrompt";
            attr.Description = "theDescription";
            attr.GroupName = "theGroupName";

            Assert.AreEqual("theShortName", attr.GetShortName());
            Assert.AreEqual("theName", attr.GetName());
            Assert.AreEqual("thePrompt", attr.GetPrompt());
            Assert.AreEqual("theDescription", attr.GetDescription());
            Assert.AreEqual("theGroupName", attr.GetGroupName());

            attr.ShortName = String.Empty;
            attr.Name = String.Empty;
            attr.Prompt = String.Empty;
            attr.Description = String.Empty;
            attr.GroupName = String.Empty;

            Assert.AreEqual(String.Empty, attr.GetShortName());
            Assert.AreEqual(String.Empty, attr.GetName());
            Assert.AreEqual(String.Empty, attr.GetPrompt());
            Assert.AreEqual(String.Empty, attr.GetDescription());
            Assert.AreEqual(String.Empty, attr.GetGroupName());
        }
Пример #12
0
        public void Prompt_Get_Set(string value)
        {
            DisplayAttribute attribute = new DisplayAttribute();

            attribute.Prompt = value;

            Assert.Equal(value, attribute.Prompt);
            Assert.Equal(value == null, attribute.GetPrompt() == null);

            // Set again, to cover the setter avoiding operations if the value is the same
            attribute.Prompt = value;
            Assert.Equal(value, attribute.Prompt);
        }
Пример #13
0
        private void EnsureDisplay()
        {
            DisplayAttribute customAttribute = GetCustomAttribute <DisplayAttribute>();

            if (customAttribute == null)
            {
                return;
            }
            meta.ShouldAdd        = customAttribute.GetAutoGenerateField();
            meta.GroupDisplayName = customAttribute.GetGroupName();
            meta.HeaderText       = customAttribute.GetName();
            meta.Watermark        = customAttribute.GetPrompt();
        }
        public void StringProperties_GetUnSetProperties_ReturnsNull()
        {
            var display = new DisplayAttribute();

            Assert.IsNull(display.Name);
            Assert.IsNull(display.ShortName);
            Assert.IsNull(display.Prompt);
            Assert.IsNull(display.Description);
            Assert.IsNull(display.GroupName);

            Assert.IsNull(display.GetName());
            Assert.IsNull(display.GetShortName());
            Assert.IsNull(display.GetPrompt());
            Assert.IsNull(display.GetDescription());
            Assert.IsNull(display.GetGroupName());
        }
        public void StringProperties_ReturnLiteralValues_Success()
        {
            var display = new DisplayAttribute()
            {
                Name        = "Name",
                ShortName   = "ShortName",
                Prompt      = "Prompt",
                Description = "Description",
                GroupName   = "GroupName"
            };

            Assert.AreEqual("Name", display.GetName());
            Assert.AreEqual("ShortName", display.GetShortName());
            Assert.AreEqual("Prompt", display.GetPrompt());
            Assert.AreEqual("Description", display.GetDescription());
            Assert.AreEqual("GroupName", display.GetGroupName());
        }
Пример #16
0
        public void Attributes_Cities_Entity_Display_On_Property_Resourced()
        {
            DisplayAttribute attr = ExpectPropertyAttribute <DisplayAttribute>(typeof(City), "Name");

            Assert.AreEqual("CityCaption", attr.ShortName);
            Assert.AreEqual("Name of City", attr.GetShortName());

            Assert.AreEqual("CityName", attr.Name);
            Assert.AreEqual("CityName", attr.GetName());

            Assert.AreEqual("CityPrompt", attr.Prompt);
            Assert.AreEqual("Enter the city name", attr.GetPrompt());

            Assert.AreEqual("CityHelpText", attr.Description);
            Assert.AreEqual("This is the name of the city", attr.GetDescription());

            Assert.AreEqual(typeof(Cities.Cities_Resources), attr.ResourceType);;
        }
        public void StringProperties_ReturnLocalizedValues_Success()
        {
            var display = new DisplayAttribute()
            {
                ResourceType = typeof(GoodResources),
                Name         = "Name",
                ShortName    = "ShortName",
                Prompt       = "Prompt",
                Description  = "Description",
                GroupName    = "GroupName"
            };

            Assert.AreEqual(GoodResources.Name, display.GetName());
            Assert.AreEqual(GoodResources.ShortName, display.GetShortName());
            Assert.AreEqual(GoodResources.Prompt, display.GetPrompt());
            Assert.AreEqual(GoodResources.Description, display.GetDescription());
            Assert.AreEqual(GoodResources.GroupName, display.GetGroupName());
        }
Пример #18
0
        public ModelMetadata BuildUp(ModelMetadata metadata, IEnumerable <Attribute> attributes,
                                     Type containerType,
                                     Func <object> modelAccessor,
                                     Type modelType,
                                     string propertyName)
        {
            // Prefer [Display(Name="")] to [DisplayName]
            DisplayAttribute display = attributes.OfType <DisplayAttribute>().FirstOrDefault();

            if (display != null)
            {
                string name = display.GetName();
                if (name != null)
                {
                    metadata.DisplayName = name;
                }

                // There was no 3.5 way to set these values
                metadata.Description      = display.GetDescription();
                metadata.ShortDisplayName = display.GetShortName();
                metadata.Watermark        = display.GetPrompt();
            }

            // Prefer [Editable] to [ReadOnly]
            EditableAttribute editable = attributes.OfType <EditableAttribute>().FirstOrDefault();

            if (editable != null)
            {
                metadata.IsReadOnly = !editable.AllowEdit;
            }

            // If [DisplayFormat(HtmlEncode=false)], set a data type name of "Html"
            // (if they didn't already set a data type)
            DisplayFormatAttribute displayFormat = attributes.OfType <DisplayFormatAttribute>().FirstOrDefault();

            if (displayFormat != null &&
                !displayFormat.HtmlEncode &&
                String.IsNullOrWhiteSpace(metadata.DataTypeName))
            {
                metadata.DataTypeName = DataType.Html.ToString();
            }

            return(metadata);
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"> </typeparam>
        /// <param name="obj"> </param>
        /// <param name="propertyName"> </param>
        /// <returns> </returns>
        public static string GetPropertyPromptData <T>(this T obj, string propertyName) where T : NotifyPropertyBase
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                return(string.Empty);
            }
            Type         tp    = obj.GetType();
            PropertyInfo pi    = tp.GetProperty(propertyName);
            var          value = pi.GetValue(obj, null);

            object[] Attributes    = pi.GetCustomAttributes(false);
            string   strPromptData = "";

            if (Attributes != null && Attributes.Length > 0)
            {
                var attribute = Attributes.FirstOrDefault(o => o is DisplayAttribute);

                if (attribute != null)
                {
                    try
                    {
                        DisplayAttribute vAttribute = attribute as DisplayAttribute;
                        if (vAttribute.ResourceType == typeof(Common.LanguageResource))
                        {
                            strPromptData = Common.LangHelper.GetValue(vAttribute.ShortName, vAttribute.Prompt, "prompt");
                        }

                        if (String.IsNullOrWhiteSpace(strPromptData))
                        {
                            if (vAttribute.ResourceType == typeof(Common.LanguageResource))
                            {
                                vAttribute.ResourceType = null;
                            }
                            strPromptData = vAttribute.GetPrompt();
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
            }
            return(strPromptData);
        }
Пример #20
0
        public void Ctor()
        {
            DisplayAttribute attribute = new DisplayAttribute();
            Assert.Null(attribute.ShortName);
            Assert.Null(attribute.GetShortName());

            Assert.Null(attribute.Name);
            Assert.Null(attribute.GetName());

            Assert.Null(attribute.Description);
            Assert.Null(attribute.GetDescription());

            Assert.Null(attribute.Prompt);
            Assert.Null(attribute.GetPrompt());

            Assert.Null(attribute.GroupName);
            Assert.Null(attribute.GetGroupName());

            Assert.Null(attribute.ResourceType);
        }
        public void AllProperties_WriteOnlyResource_ThrowsInvalidOperationException()
        {
            var resourceType = typeof(BadResources);
            var resourceKey  = "WriteOnlyString";
            var display      = new DisplayAttribute()
            {
                ResourceType = resourceType,
                Name         = resourceKey,
                ShortName    = resourceKey,
                Prompt       = resourceKey,
                Description  = resourceKey,
                GroupName    = resourceKey
            };

            ExceptionAssert.Throws <InvalidOperationException>(() => display.GetName(), string.Format(localization_failed_message, "Name", resourceType, resourceKey));
            ExceptionAssert.Throws <InvalidOperationException>(() => display.GetShortName(), string.Format(localization_failed_message, "ShortName", resourceType, resourceKey));
            ExceptionAssert.Throws <InvalidOperationException>(() => display.GetPrompt(), string.Format(localization_failed_message, "Prompt", resourceType, resourceKey));
            ExceptionAssert.Throws <InvalidOperationException>(() => display.GetDescription(), string.Format(localization_failed_message, "Description", resourceType, resourceKey));
            ExceptionAssert.Throws <InvalidOperationException>(() => display.GetGroupName(), string.Format(localization_failed_message, "GroupName", resourceType, resourceKey));
        }
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType,
                                                        Func <object> modelAccessor, Type modelType, string propertyName)
        {
            ModelMetadata metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);

            DisplayAttribute display = attributes.OfType <DisplayAttribute>().FirstOrDefault();

            if (display != null)
            {
                string name = display.GetName();
                if (name != null)
                {
                    metadata.DisplayName = name;
                }

                metadata.Description      = display.GetDescription();
                metadata.ShortDisplayName = display.GetShortName();
                metadata.Watermark        = display.GetPrompt();
            }

            EditableAttribute editable = attributes.OfType <EditableAttribute>().FirstOrDefault();

            if (editable != null)
            {
                metadata.IsReadOnly = !editable.AllowEdit;
            }

            DisplayFormatAttribute displayFormat = attributes.OfType <DisplayFormatAttribute>().FirstOrDefault();

            if (displayFormat != null && !displayFormat.HtmlEncode && String.IsNullOrWhiteSpace(metadata.DataTypeName))
            {
                metadata.DataTypeName = DataType.Html.ToString();
            }

            foreach (IMetadataAware awareAttribute in attributes.OfType <IMetadataAware>())
            {
                awareAttribute.OnMetadataCreated(metadata);
            }

            return(metadata);
        }
Пример #23
0
        public void Ctor()
        {
            DisplayAttribute attribute = new DisplayAttribute();

            Assert.Null(attribute.ShortName);
            Assert.Null(attribute.GetShortName());

            Assert.Null(attribute.Name);
            Assert.Null(attribute.GetName());

            Assert.Null(attribute.Description);
            Assert.Null(attribute.GetDescription());

            Assert.Null(attribute.Prompt);
            Assert.Null(attribute.GetPrompt());

            Assert.Null(attribute.GroupName);
            Assert.Null(attribute.GetGroupName());

            Assert.Null(attribute.ResourceType);
        }
Пример #24
0
        public void DisplayAttribute_Fail_No_Getter_Resource()
        {
            DisplayAttribute attr = new DisplayAttribute();

            attr.ResourceType = typeof(DisplayAttribute_Resources);
            attr.ShortName    = "NoGetter";
            attr.Name         = "NoGetter";
            attr.Prompt       = "NoGetter";
            attr.Description  = "NoGetter";
            attr.GroupName    = "NoGetter";

            string shortNameError   = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "ShortName", attr.ResourceType.FullName, attr.ShortName);
            string nameError        = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Name", attr.ResourceType.FullName, attr.Name);
            string promptError      = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Prompt", attr.ResourceType.FullName, attr.Prompt);
            string descriptionError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Description", attr.ResourceType.FullName, attr.Description);
            string groupNameError   = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "GroupName", attr.ResourceType.FullName, attr.GroupName);

            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetShortName(); }, shortNameError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetName(); }, nameError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetPrompt(); }, promptError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetDescription(); }, descriptionError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetGroupName(); }, groupNameError);
        }
        //public override IEnumerable<ModelMetadata> GetMetadataForProperties(object container, Type containerType)
        //{
        //  return base.GetMetadataForProperties(container, containerType);
        //}

        //public override ModelMetadata GetMetadataForType(Func<object> modelAccessor, Type modelType)
        //{
        //  return base.GetMetadataForType(modelAccessor, modelType);
        //}

        //public override ModelMetadata GetMetadataForProperty(Func<object> modelAccessor, Type containerType, string propertyName)
        //{
        //  return base.GetMetadataForProperty(modelAccessor, containerType, propertyName);
        //}

        //protected override ModelMetadata GetMetadataForProperty(Func<object> modelAccessor, Type containerType, System.ComponentModel.PropertyDescriptor propertyDescriptor)
        //{
        //  return base.GetMetadataForProperty(modelAccessor, containerType, propertyDescriptor);
        //}
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            //Reflected from base class
            List <Attribute>       list = new List <Attribute>(attributes);
            DisplayColumnAttribute displayColumnAttribute = Enumerable.FirstOrDefault <DisplayColumnAttribute>(Enumerable.OfType <DisplayColumnAttribute>((IEnumerable)list));

            DataAnnotationsModelMetadata annotationsModelMetadata = null;

            //brl additions
            //if this is a BOV backed object
            if (containerType != null && Attribute.IsDefined(containerType, typeof(DryLogicObjectAttribute)) && propertyName != "OI")
            {
                Object         container = null;
                ObjectInstance oi        = null;
                //By having this code here instead of in GetMetadataForProperty, some of the normal features like ui hint will work
                if (modelAccessor != null)
                {
                    var rootModelType = modelAccessor.Target.GetType();
                    var field         = rootModelType.GetField("container");
                    if (field != null)
                    {
                        container = field.GetValue(modelAccessor.Target);
                        //if we don't have a reference to the container yet...
                        if (container.GetType() != containerType)
                        {
                            //...then try to break down the expression to get it
                            //get the expression as text, ie "model.EmployeeViewModel.MyEmployee" and split it
                            var expressionParts = ((LambdaExpression)rootModelType.GetField("expression").GetValue(modelAccessor.Target)).Body.ToString().Split('.');
                            //var expressionParts = new string[] { };

                            //loop thru the parts in the middle
                            for (int i = 1; i < expressionParts.Length - 1; i++)
                            {
                                container = container.GetType().GetProperty(expressionParts[i]).GetValue(container);
                            }
                        }
                        //could use an attribute instead to identify the object instance
                        oi = ObjectInstance.GetObjectInstance(container);

                        if (oi != null)//not really sure how this woudl fail at this point
                        {
                            annotationsModelMetadata           = new PropertyValueMetadata(this, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute);
                            annotationsModelMetadata.Container = container;
                            //internally, setting model wipes out modelAccessor (caching of sorts)
                            annotationsModelMetadata.Model        = oi.PropertyValues[propertyName];
                            annotationsModelMetadata.TemplateHint = "PropertyValue";
                        }
                    }
                }
            }
            if (annotationsModelMetadata == null)
            {
                annotationsModelMetadata = new DataAnnotationsModelMetadata(this, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute);
            }


            HiddenInputAttribute hiddenInputAttribute = Enumerable.FirstOrDefault <HiddenInputAttribute>(Enumerable.OfType <HiddenInputAttribute>((IEnumerable)list));

            if (hiddenInputAttribute != null)
            {
                annotationsModelMetadata.TemplateHint        = "HiddenInput";
                annotationsModelMetadata.HideSurroundingHtml = !hiddenInputAttribute.DisplayValue;
            }
            IEnumerable <UIHintAttribute> source = Enumerable.OfType <UIHintAttribute>((IEnumerable)list);
            UIHintAttribute uiHintAttribute      = Enumerable.FirstOrDefault <UIHintAttribute>(source, (Func <UIHintAttribute, bool>)(a => string.Equals(a.PresentationLayer, "MVC", StringComparison.OrdinalIgnoreCase))) ?? Enumerable.FirstOrDefault <UIHintAttribute>(source, (Func <UIHintAttribute, bool>)(a => string.IsNullOrEmpty(a.PresentationLayer)));

            if (uiHintAttribute != null)
            {
                annotationsModelMetadata.TemplateHint = uiHintAttribute.UIHint;
            }
            DataTypeAttribute attribute = Enumerable.FirstOrDefault <DataTypeAttribute>(Enumerable.OfType <DataTypeAttribute>((IEnumerable)list));

            if (attribute != null)
            {
                annotationsModelMetadata.DataTypeName = DataTypeUtil.ToDataTypeName(attribute, (Func <DataTypeAttribute, bool>)null);
            }
            EditableAttribute editableAttribute = Enumerable.FirstOrDefault <EditableAttribute>(Enumerable.OfType <EditableAttribute>((IEnumerable)attributes));

            if (editableAttribute != null)
            {
                annotationsModelMetadata.IsReadOnly = !editableAttribute.AllowEdit;
            }
            else
            {
                ReadOnlyAttribute readOnlyAttribute = Enumerable.FirstOrDefault <ReadOnlyAttribute>(Enumerable.OfType <ReadOnlyAttribute>((IEnumerable)list));
                if (readOnlyAttribute != null)
                {
                    annotationsModelMetadata.IsReadOnly = readOnlyAttribute.IsReadOnly;
                }
            }
            DisplayFormatAttribute displayFormatAttribute = Enumerable.FirstOrDefault <DisplayFormatAttribute>(Enumerable.OfType <DisplayFormatAttribute>((IEnumerable)list));

            if (displayFormatAttribute == null && attribute != null)
            {
                displayFormatAttribute = attribute.DisplayFormat;
            }
            if (displayFormatAttribute != null)
            {
                annotationsModelMetadata.NullDisplayText          = displayFormatAttribute.NullDisplayText;
                annotationsModelMetadata.DisplayFormatString      = displayFormatAttribute.DataFormatString;
                annotationsModelMetadata.ConvertEmptyStringToNull = displayFormatAttribute.ConvertEmptyStringToNull;
                if (displayFormatAttribute.ApplyFormatInEditMode)
                {
                    annotationsModelMetadata.EditFormatString = displayFormatAttribute.DataFormatString;
                }
                if (!displayFormatAttribute.HtmlEncode && string.IsNullOrWhiteSpace(annotationsModelMetadata.DataTypeName))
                {
                    annotationsModelMetadata.DataTypeName = DataTypeUtil.HtmlTypeName;
                }
            }
            ScaffoldColumnAttribute scaffoldColumnAttribute = Enumerable.FirstOrDefault <ScaffoldColumnAttribute>(Enumerable.OfType <ScaffoldColumnAttribute>((IEnumerable)list));

            if (scaffoldColumnAttribute != null)
            {
                annotationsModelMetadata.ShowForDisplay = annotationsModelMetadata.ShowForEdit = scaffoldColumnAttribute.Scaffold;
            }
            DisplayAttribute displayAttribute = Enumerable.FirstOrDefault <DisplayAttribute>(Enumerable.OfType <DisplayAttribute>((IEnumerable)attributes));
            string           str = (string)null;

            if (displayAttribute != null)
            {
                annotationsModelMetadata.Description      = displayAttribute.GetDescription();
                annotationsModelMetadata.ShortDisplayName = displayAttribute.GetShortName();
                annotationsModelMetadata.Watermark        = displayAttribute.GetPrompt();
                annotationsModelMetadata.Order            = displayAttribute.GetOrder() ?? 10000;
                str = displayAttribute.GetName();
            }
            if (str != null)
            {
                annotationsModelMetadata.DisplayName = str;
            }
            else
            {
                DisplayNameAttribute displayNameAttribute = Enumerable.FirstOrDefault <DisplayNameAttribute>(Enumerable.OfType <DisplayNameAttribute>((IEnumerable)list));
                if (displayNameAttribute != null)
                {
                    annotationsModelMetadata.DisplayName = displayNameAttribute.DisplayName;
                }
            }
            if (Enumerable.FirstOrDefault <RequiredAttribute>(Enumerable.OfType <RequiredAttribute>((IEnumerable)list)) != null)
            {
                annotationsModelMetadata.IsRequired = true;
            }
            return((ModelMetadata)annotationsModelMetadata);
        }
        public void DisplayAttribute_Resourced_Properties_Wrong_Keys() {
            DisplayAttribute attr = new DisplayAttribute();

            attr.ResourceType = typeof(DisplayAttribute_Resources);

            attr.ShortName = "notAKey1";
            attr.Name = "notAKey2";
            attr.Prompt = "notAKey3";
            attr.Description = "notAKey4";
            attr.GroupName = "notAKey5";

            Assert.AreEqual("notAKey1", attr.ShortName);
            Assert.AreEqual("notAKey2", attr.Name);
            Assert.AreEqual("notAKey3", attr.Prompt);
            Assert.AreEqual("notAKey4", attr.Description);
            Assert.AreEqual("notAKey5", attr.GroupName);

            string shortNameError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "ShortName", attr.ResourceType.FullName, attr.ShortName);
            string nameError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Name", attr.ResourceType.FullName, attr.Name);
            string promptError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Prompt", attr.ResourceType.FullName, attr.Prompt);
            string descriptionError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Description", attr.ResourceType.FullName, attr.Description);
            string groupNameError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "GroupName", attr.ResourceType.FullName, attr.GroupName);

            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetShortName(); }, shortNameError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetName(); }, nameError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetPrompt(); }, promptError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetDescription(); }, descriptionError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetGroupName(); }, groupNameError);
        }
Пример #27
0
        public void Prompt_Get_Set(string value)
        {
            DisplayAttribute attribute = new DisplayAttribute();
            attribute.Prompt = value;

            Assert.Equal(value, attribute.Prompt);
            Assert.Equal(value == null, attribute.GetPrompt() == null);

            // Set again, to cover the setter avoiding operations if the value is the same
            attribute.Prompt = value;
            Assert.Equal(value, attribute.Prompt);
        }
 public string GetPrompt()
 {
     return(_innerAttribute.GetPrompt());
 }
        public override AttributeDeclaration GetAttributeDeclaration(Attribute attribute)
        {
            DisplayAttribute     displayAttribute     = (DisplayAttribute)attribute;
            AttributeDeclaration attributeDeclaration = new AttributeDeclaration(typeof(DisplayAttribute));

            // By convention, the attribute parameters are not validated until an attempt is made to
            // access the resources.  We do the following probe merely to trigger this validation process.
            // An InvalidOperationException will be thrown if the attribute is ill-formed.
            Type attributeType = attribute.GetType();

            try
            {
                displayAttribute.GetName();
            }
            catch (InvalidOperationException ex)
            {
                throw new AttributeBuilderException(ex, attributeType, "Name");
            }

            try
            {
                displayAttribute.GetShortName();
            }
            catch (InvalidOperationException ex)
            {
                throw new AttributeBuilderException(ex, attributeType, "ShortName");
            }

            try
            {
                displayAttribute.GetDescription();
            }
            catch (InvalidOperationException ex)
            {
                throw new AttributeBuilderException(ex, attributeType, "Description");
            }

            try
            {
                displayAttribute.GetPrompt();
            }
            catch (InvalidOperationException ex)
            {
                throw new AttributeBuilderException(ex, attributeType, "Prompt");
            }

            // Add AutoGenerateField
            if (displayAttribute.GetAutoGenerateField().HasValue)
            {
                attributeDeclaration.NamedParameters.Add("AutoGenerateField", displayAttribute.AutoGenerateField);
            }

            // Add AutoGenerateFilter
            if (displayAttribute.GetAutoGenerateFilter().HasValue)
            {
                attributeDeclaration.NamedParameters.Add("AutoGenerateFilter", displayAttribute.AutoGenerateFilter);
            }

            // Add Description
            if (!string.IsNullOrEmpty(displayAttribute.Description))
            {
                attributeDeclaration.NamedParameters.Add("Description", displayAttribute.Description);
            }

            // Add GroupName
            if (!string.IsNullOrEmpty(displayAttribute.GroupName))
            {
                attributeDeclaration.NamedParameters.Add("GroupName", displayAttribute.GroupName);
            }

            // Add Name
            if (!string.IsNullOrEmpty(displayAttribute.Name))
            {
                attributeDeclaration.NamedParameters.Add("Name", displayAttribute.Name);
            }

            // Add Order
            if (displayAttribute.GetOrder().HasValue)
            {
                attributeDeclaration.NamedParameters.Add("Order", displayAttribute.Order);
            }

            // Add Prompt
            if (!string.IsNullOrEmpty(displayAttribute.Prompt))
            {
                attributeDeclaration.NamedParameters.Add("Prompt", displayAttribute.Prompt);
            }

            // Add ResourceType
            if (displayAttribute.ResourceType != null)
            {
                attributeDeclaration.NamedParameters.Add("ResourceType", displayAttribute.ResourceType);
            }

            // Add ShortName
            if (!string.IsNullOrEmpty(displayAttribute.ShortName))
            {
                attributeDeclaration.NamedParameters.Add("ShortName", displayAttribute.ShortName);
            }

            return(attributeDeclaration);
        }
Пример #30
0
        public void DisplayAttribute_Resourced_Properties_Wrong_Keys()
        {
            DisplayAttribute attr = new DisplayAttribute();

            attr.ResourceType = typeof(DisplayAttribute_Resources);

            attr.ShortName   = "notAKey1";
            attr.Name        = "notAKey2";
            attr.Prompt      = "notAKey3";
            attr.Description = "notAKey4";
            attr.GroupName   = "notAKey5";

            Assert.AreEqual("notAKey1", attr.ShortName);
            Assert.AreEqual("notAKey2", attr.Name);
            Assert.AreEqual("notAKey3", attr.Prompt);
            Assert.AreEqual("notAKey4", attr.Description);
            Assert.AreEqual("notAKey5", attr.GroupName);

            string shortNameError   = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "ShortName", attr.ResourceType.FullName, attr.ShortName);
            string nameError        = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Name", attr.ResourceType.FullName, attr.Name);
            string promptError      = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Prompt", attr.ResourceType.FullName, attr.Prompt);
            string descriptionError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Description", attr.ResourceType.FullName, attr.Description);
            string groupNameError   = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "GroupName", attr.ResourceType.FullName, attr.GroupName);

            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetShortName(); }, shortNameError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetName(); }, nameError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetPrompt(); }, promptError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetDescription(); }, descriptionError);
            ExceptionHelper.ExpectException <InvalidOperationException>(() => { string s = attr.GetGroupName(); }, groupNameError);
        }
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            List <Attribute>             attributeList          = new List <Attribute>(attributes);
            DisplayColumnAttribute       displayColumnAttribute = attributeList.OfType <DisplayColumnAttribute>().FirstOrDefault();
            DataAnnotationsModelMetadata result = new DataAnnotationsModelMetadata(this, containerType, modelAccessor, modelType, propertyName, displayColumnAttribute);

            // Do [HiddenInput] before [UIHint], so you can override the template hint
            HiddenInputAttribute hiddenInputAttribute = attributeList.OfType <HiddenInputAttribute>().FirstOrDefault();

            if (hiddenInputAttribute != null)
            {
                result.TemplateHint        = "HiddenInput";
                result.HideSurroundingHtml = !hiddenInputAttribute.DisplayValue;
            }

            // We prefer [UIHint("...", PresentationLayer = "MVC")] but will fall back to [UIHint("...")]
            IEnumerable <UIHintAttribute> uiHintAttributes = attributeList.OfType <UIHintAttribute>();
            UIHintAttribute uiHintAttribute = uiHintAttributes.FirstOrDefault(a => String.Equals(a.PresentationLayer, "MVC", StringComparison.OrdinalIgnoreCase))
                                              ?? uiHintAttributes.FirstOrDefault(a => String.IsNullOrEmpty(a.PresentationLayer));

            if (uiHintAttribute != null)
            {
                result.TemplateHint = uiHintAttribute.UIHint;
            }

            DataTypeAttribute dataTypeAttribute = attributeList.OfType <DataTypeAttribute>().FirstOrDefault();

            if (dataTypeAttribute != null)
            {
                result.DataTypeName = dataTypeAttribute.ToDataTypeName();
            }

            EditableAttribute editable = attributes.OfType <EditableAttribute>().FirstOrDefault();

            if (editable != null)
            {
                result.IsReadOnly = !editable.AllowEdit;
            }
            else
            {
                ReadOnlyAttribute readOnlyAttribute = attributeList.OfType <ReadOnlyAttribute>().FirstOrDefault();
                if (readOnlyAttribute != null)
                {
                    result.IsReadOnly = readOnlyAttribute.IsReadOnly;
                }
            }

            DisplayFormatAttribute displayFormatAttribute = attributeList.OfType <DisplayFormatAttribute>().FirstOrDefault();

            if (displayFormatAttribute == null && dataTypeAttribute != null)
            {
                displayFormatAttribute = dataTypeAttribute.DisplayFormat;
            }
            if (displayFormatAttribute != null)
            {
                result.NullDisplayText          = displayFormatAttribute.NullDisplayText;
                result.DisplayFormatString      = displayFormatAttribute.DataFormatString;
                result.ConvertEmptyStringToNull = displayFormatAttribute.ConvertEmptyStringToNull;

                if (displayFormatAttribute.ApplyFormatInEditMode)
                {
                    result.EditFormatString = displayFormatAttribute.DataFormatString;
                }

                if (!displayFormatAttribute.HtmlEncode && String.IsNullOrWhiteSpace(result.DataTypeName))
                {
                    result.DataTypeName = DataTypeUtil.HtmlTypeName;
                }
            }

            ScaffoldColumnAttribute scaffoldColumnAttribute = attributeList.OfType <ScaffoldColumnAttribute>().FirstOrDefault();

            if (scaffoldColumnAttribute != null)
            {
                result.ShowForDisplay = result.ShowForEdit = scaffoldColumnAttribute.Scaffold;
            }

            DisplayAttribute display = attributes.OfType <DisplayAttribute>().FirstOrDefault();
            string           name    = null;

            if (display != null)
            {
                result.Description      = display.GetDescription();
                result.ShortDisplayName = display.GetShortName();
                result.Watermark        = display.GetPrompt();
                result.Order            = display.GetOrder() ?? ModelMetadata.DefaultOrder;

                name = display.GetName();
            }

            if (name != null)
            {
                result.DisplayName = name;
            }
            else
            {
                DisplayNameAttribute displayNameAttribute = attributeList.OfType <DisplayNameAttribute>().FirstOrDefault();
                if (displayNameAttribute != null)
                {
                    result.DisplayName = displayNameAttribute.DisplayName;
                }
            }

            RequiredAttribute requiredAttribute = attributeList.OfType <RequiredAttribute>().FirstOrDefault();

            if (requiredAttribute != null)
            {
                result.IsRequired = true;
            }

            return(result);
        }
 public void DisplayAttribute_GetPrompt_Does_Not_Fall_Back() {
     DisplayAttribute attr = new DisplayAttribute { ShortName = "ShortName", Name = "Name", Description = "Description", GroupName = "GroupName" };
     Assert.IsNull(attr.GetPrompt(), "GetPrompt should NOT fall back onto any other values");
 }
Пример #33
0
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes,
                                                        Type containerType,
                                                        Func <object> modelAccessor,
                                                        Type modelType,
                                                        string propertyName)
        {
            ModelMetadata metadata = base.CreateMetadata(attributes,
                                                         containerType,
                                                         modelAccessor,
                                                         modelType,
                                                         propertyName);

            // Prefer [Display(Name="")] to [DisplayName]
            DisplayAttribute display = attributes.OfType <DisplayAttribute>().FirstOrDefault();

            if (display != null)
            {
                string name = display.GetName();
                if (name != null)
                {
                    metadata.DisplayName = name;
                }

                // There was no 3.5 way to set these values
                metadata.Description      = display.GetDescription();
                metadata.ShortDisplayName = display.GetShortName();
                metadata.Watermark        = display.GetPrompt();
            }

            // Prefer [Editable] to [ReadOnly]
            EditableAttribute editable = attributes.OfType <EditableAttribute>().FirstOrDefault();

            if (editable != null)
            {
                metadata.IsReadOnly = !editable.AllowEdit;
            }

            // If [DisplayFormat(HtmlEncode=false)], set a data type name of "Html"
            // (if they didn't already set a data type)
            DisplayFormatAttribute displayFormat = attributes.OfType <DisplayFormatAttribute>().FirstOrDefault();

            if (displayFormat != null &&
                !displayFormat.HtmlEncode &&
                String.IsNullOrWhiteSpace(metadata.DataTypeName))
            {
                metadata.DataTypeName = DataType.Html.ToString();
            }

            // Title Attribute
            TitleAttribute titleAttribute = attributes.OfType <TitleAttribute>().FirstOrDefault();

            if (titleAttribute != null)
            {
                // metadata.AdditionalValues.Add("Title", titleAttribute.Title);
                metadata.DisplayName = titleAttribute.Title;
            }

            // Section Attribute
            List <SectionAttribute> sectionAttributeList = attributes.OfType <SectionAttribute>().ToList();

            sectionAttributeList.Sort((x, y) => x.DisplayOrder.CompareTo(y.DisplayOrder));
            if (sectionAttributeList.Count > 0)
            {
                metadata.AdditionalValues.Add("SectionList", sectionAttributeList);
            }

            // Width
            WidthAttribute widthAttribute = attributes.OfType <WidthAttribute>().FirstOrDefault();

            if (widthAttribute != null)
            {
                metadata.AdditionalValues.Add("Width", widthAttribute.Columns);
            }

            // EndRow
            StartRowAttribute endRowAttribute = attributes.OfType <StartRowAttribute>().FirstOrDefault();

            if (endRowAttribute != null)
            {
                metadata.AdditionalValues.Add("StartRow", true);
            }

            // Button
            List <ButtonAttribute> buttonAttributeList = attributes.OfType <ButtonAttribute>().ToList();

            buttonAttributeList.Sort((x, y) => x.DisplayOrder.CompareTo(y.DisplayOrder));
            if (buttonAttributeList.Count > 0)
            {
                metadata.AdditionalValues.Add("ButtonList", buttonAttributeList);
            }

            // ClientData
            if (containerType != null)
            {
                PropertyInfo propertyInfo = containerType.GetProperty(propertyName);
                if (propertyInfo != null)
                {
                    List <AddDataAttributeAttribute> addDataAttributeList = propertyInfo.GetCustomAttributes <AddDataAttributeAttribute>().ToList();
                    if (addDataAttributeList.Count > 0)
                    {
                        metadata.AdditionalValues.Add("AddDataAttributeList", addDataAttributeList);
                    }

                    List <AddAttributeAttribute> addAttributeAttributeList = propertyInfo.GetCustomAttributes <AddAttributeAttribute>().ToList();
                    if (addAttributeAttributeList.Count > 0)
                    {
                        metadata.AdditionalValues.Add("AddAttributeAttributeList", addAttributeAttributeList);
                    }
                }
            }

            // restricted
            RestrictedAttribute.CreateMetadata(metadata, attributes);

            return(metadata);
        }
 public string GetPrompt() => _display.GetPrompt();
        public void DisplayAttribute_Fail_No_Getter_Resource() {
            DisplayAttribute attr = new DisplayAttribute();
            attr.ResourceType = typeof(DisplayAttribute_Resources);
            attr.ShortName = "NoGetter";
            attr.Name = "NoGetter";
            attr.Prompt = "NoGetter";
            attr.Description = "NoGetter";
            attr.GroupName = "NoGetter";

            string shortNameError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "ShortName", attr.ResourceType.FullName, attr.ShortName);
            string nameError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Name", attr.ResourceType.FullName, attr.Name);
            string promptError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Prompt", attr.ResourceType.FullName, attr.Prompt);
            string descriptionError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "Description", attr.ResourceType.FullName, attr.Description);
            string groupNameError = String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.LocalizableString_LocalizationFailed, "GroupName", attr.ResourceType.FullName, attr.GroupName);

            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetShortName(); }, shortNameError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetName(); }, nameError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetPrompt(); }, promptError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetDescription(); }, descriptionError);
            ExceptionHelper.ExpectException<InvalidOperationException>(() => { string s = attr.GetGroupName(); }, groupNameError);
        }