コード例 #1
0
        public override AttributeDeclaration GetAttributeDeclaration(Attribute attribute)
        {
            UIHintAttribute uiHintAttribute = (UIHintAttribute)attribute;

            // We override this build method only to deal with the control parameters
            // which cannot be generated by the standard builder.  If there are no
            // control parameters, let the standard builder do the work.
            IDictionary <string, object> controlParams = uiHintAttribute.ControlParameters;

            if (controlParams == null || controlParams.Count == 0)
            {
                return(base.GetAttributeDeclaration(attribute));
            }

            AttributeDeclaration attributeDeclaration = new AttributeDeclaration(typeof(UIHintAttribute));

            // UIHint[("uiHint", "presentationLayer")]
            attributeDeclaration.ConstructorArguments.Add(uiHintAttribute.UIHint);
            attributeDeclaration.ConstructorArguments.Add(uiHintAttribute.PresentationLayer);

            // UIHint[("uiHint", "presentationLayer", ...)] -- fill in all the optional params from control parameters
            foreach (KeyValuePair <string, object> item in controlParams)
            {
                attributeDeclaration.ConstructorArguments.Add(item.Key);
                attributeDeclaration.ConstructorArguments.Add(item.Value);
            }

            return(attributeDeclaration);
        }
コード例 #2
0
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            //不希望覆寫太多東西,所以大部分還是用base的CreateMetadata方法
            ModelMetadata metadata = base.CreateMetadata(attributes,
                                                         containerType,
                                                         modelAccessor,
                                                         modelType,
                                                         propertyName);

            List <Attribute> attributeList = new List <Attribute>(attributes);

            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));

            //如果有UIHint屬性,就將他的參數塞到ModelMetadata.AdditionalValues裡面
            //Key是UIHintTemplateControlParameters
            if (uiHintAttribute != null)
            {
                if (metadata.AdditionalValues.ContainsKey("UIHintTemplateControlParameters"))
                {
                    throw new ArgumentException("Metadate.AdditionalValues已存在 \"UIHintTemplateControlParameters\"這個Key,請更換擴充UIHintAttribute的Key值。");
                }

                metadata.AdditionalValues.Add("UIHintTemplateControlParameters", uiHintAttribute.ControlParameters);
            }
            return(metadata);
        }
コード例 #3
0
ファイル: Excel.cs プロジェクト: Egorik-555/BezvizSystem
        private void MakeHead <T>(T item)
        {
            Type t = typeof(T);
            int  i = 0;

            foreach (var info in t.GetProperties())
            {
                DisplayAttribute dispAttr = (DisplayAttribute)Attribute.GetCustomAttribute(info, typeof(DisplayAttribute));
                UIHintAttribute  uiAttr   = (UIHintAttribute)Attribute.GetCustomAttribute(info, typeof(UIHintAttribute));

                if (uiAttr != null && uiAttr.UIHint == "HiddenInput")
                {
                    continue;
                }

                if (dispAttr != null)
                {
                    ws.AddCell(0, i, dispAttr.Name);
                }
                else
                {
                    ws.AddCell(0, i, info.Name);
                }
                i++;
            }
        }
コード例 #4
0
ファイル: Excel.cs プロジェクト: Egorik-555/BezvizSystem
        public string InExcel <T>(IEnumerable <T> list)
        {
            if (list == null)
            {
                return(null);
            }

            Type t = typeof(T);

            MakeHead <T>(list.FirstOrDefault());

            if (list.Count() == 0)
            {
                return(wb.ExportToXML());
            }

            int r = 1;

            foreach (var item in list)
            {
                int c = 0;
                foreach (var info in t.GetProperties())
                {
                    UIHintAttribute uiAttr = (UIHintAttribute)Attribute.GetCustomAttribute(info, typeof(UIHintAttribute));
                    if (uiAttr != null && uiAttr.UIHint == "HiddenInput")
                    {
                        continue;
                    }
                    ws.AddCell(r, c, info.GetValue(item) != null ? info.GetValue(item).ToString() : "");
                    c++;
                }
                r++;
            }
            return(wb.ExportToXML());
        }
コード例 #5
0
        public void Equals_SameObjectType_WithParamsDictionary()
        {
            var a1 = new UIHintAttribute("foo", "bar", "a", 1, "b", false);
            var a2 = new UIHintAttribute("foo", "bar", "b", false, "a", 1);

            Assert.IsTrue(a1.Equals(a2));
            Assert.IsTrue(a2.Equals(a1));
        }
コード例 #6
0
        public void Equals_DoesNotThrow()
        {
            var a1 = new UIHintAttribute("foo", "bar");
            var a2 = new UIHintAttribute("foo", "bar", 1);

            Assert.IsFalse(a1.Equals(a2));
            Assert.IsFalse(a2.Equals(a1));
        }
コード例 #7
0
        public void ConstructorControlParameters_UnevenNumber()
        {
            var attr = new UIHintAttribute("", "", "");

            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                var v = attr.ControlParameters;
            }, Resources.DataAnnotationsResources.UIHintImplementation_NeedEvenNumberOfControlParameters);
        }
コード例 #8
0
        public void ConstructorControlParameters_NullKey()
        {
            var attr = new UIHintAttribute("", "", null, "value");

            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                var v = attr.ControlParameters;
            }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.UIHintImplementation_ControlParameterKeyIsNull, 0));
        }
コード例 #9
0
        public void ConstructorControlParameters_DuplicateKey()
        {
            var attr = new UIHintAttribute("", "", "key", "value1", "key", "value2");

            ExceptionHelper.ExpectException <InvalidOperationException>(delegate() {
                var v = attr.ControlParameters;
            }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.UIHintImplementation_ControlParameterKeyOccursMoreThanOnce, 2, "key"));
        }
コード例 #10
0
        public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel)
        {
            var uiHintAttribute = propertyInfo.GetAttribute <UIHintAttribute>();

            Control control;

            if (uiHintAttribute == null)
            {
                uiHintAttribute = new UIHintAttribute("");
            }

            switch (uiHintAttribute.UIHint)
            {
            case UIHints.DisplayDataGrid:
                control = ProvideGridControl(propertyInfo, viewModel);
                break;

            case UIHints.DisplayChart:
                control = ProvideChartControl(propertyInfo, viewModel, uiHintAttribute);
                break;

            case UIHints.DisplayMap:
                control = ProvideGMapControl(propertyInfo, viewModel);
                break;

            default:
                control = ProvideComboBoxControl(propertyInfo, viewModel, uiHintAttribute);
                break;
            }


            string selectedItemBindingPath = null;

            if (uiHintAttribute.ControlParameters.ContainsKey(UIHints.ItemsControlParameters.SelectedItemBindingPath))
            {
                selectedItemBindingPath = (string)uiHintAttribute.ControlParameters[UIHints.ItemsControlParameters.SelectedItemBindingPath];
            }

            if (selectedItemBindingPath != null)
            {
                //setting selected item binding to selection property
                Binding selectedItemBinding = new Binding(selectedItemBindingPath);
                control.SetBinding(Selector.SelectedItemProperty, selectedItemBinding);
            }
            else
            if (propertyInfo.HasPropertyForSelectedItem())    //check for selected item
            {
                PropertyInfo property = propertyInfo.GetPropertyForSelectedItem();

                //setting selected item binding to selection property
                Binding selectedItemBinding = property.GetBinding();
                control.SetBinding(Selector.SelectedItemProperty, selectedItemBinding);
            }


            return(control);
        }
コード例 #11
0
        private static void VerifyAttribute(UIHintAttribute attribute, string filterUIHint, string presentationLayer, IDictionary <string, object> controlParameters)
        {
            Assert.Equal(filterUIHint, attribute.UIHint);
            Assert.Equal(presentationLayer, attribute.PresentationLayer);
            Assert.Equal(controlParameters, attribute.ControlParameters);

            // ControlParameters is cached
            Assert.Same(attribute.ControlParameters, attribute.ControlParameters);
        }
コード例 #12
0
        private static void VerifyAttribute(UIHintAttribute attribute, string filterUIHint, string presentationLayer, IDictionary<string, object> controlParameters)
        {
            Assert.Equal(filterUIHint, attribute.UIHint);
            Assert.Equal(presentationLayer, attribute.PresentationLayer);
            Assert.Equal(controlParameters, attribute.ControlParameters);

            // ControlParameters is cached
            Assert.Same(attribute.ControlParameters, attribute.ControlParameters);
        }
コード例 #13
0
        public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel)
        {
            Binding binding = propertyInfo.GetBinding();


            var uiHintAttribute = propertyInfo.GetAttribute <UIHintAttribute>();

            //checking if item is for filter area...
            bool isFilterProperty = propertyInfo.IsFilterPropertyForUserInterface();

            if (isFilterProperty && uiHintAttribute == null)
            {
                //override display to DisplayDelayedBindingTextBox
                uiHintAttribute = new UIHintAttribute(UIHints.DisplayDelayedBindingTextBox);
            }

            Control control;

            if (uiHintAttribute == null)
            {
                control = ProvideDefaultControl(binding, propertyInfo);
            }
            else
            {
                switch (uiHintAttribute.UIHint)
                {
                case UIHints.DisplayRichTextBox:
                    control = ProvideRichTextBoxControl(binding, propertyInfo);
                    break;

                case UIHints.DisplayMultiLineTextBox:
                    control = ProvideDefaultControl(binding, propertyInfo, true);
                    break;

                case UIHints.DisplayDelayedBindingTextBox:
                    control = ProvideDelayedBindingTextBoxControl(binding, propertyInfo);
                    break;

                case UIHints.DisplayHyperlink:
                    control = ProvideHyperLinkControl(binding, propertyInfo, viewModel);
                    break;

                case UIHints.DisplayWebBrowser:
                    control = ProvideWebBrowserControl(binding, propertyInfo, viewModel);
                    break;

                default:
                    //warn default case
                    control = ProvideDefaultControl(binding, propertyInfo);
                    break;
                }
            }


            return(control);
        }
コード例 #14
0
        public static UIHint GetUIHint(object[] attributes)
        {
            UIHintAttribute attribute = CustomAttributeHelpers.GetAttribute <UIHintAttribute>(attributes);

            if (attribute == null)
            {
                return(0);
            }
            return(attribute.get_Hint());
        }
コード例 #15
0
 private static bool IsVariableField()
 {
     object[] array = FsmErrorChecker.attributes;
     for (int i = 0; i < array.Length; i++)
     {
         Attribute       attribute       = (Attribute)array[i];
         UIHintAttribute uIHintAttribute = attribute as UIHintAttribute;
         if (uIHintAttribute != null && uIHintAttribute.get_Hint() == 10)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #16
0
        public override FrameworkElement Bind(FrameworkElement uiElement, UIHintAttribute uiHint, PropertyInfo propInfo)
        {
            base.Bind(uiElement, uiHint, propInfo);

            uiElement.SetBinding(CheckedListBox.SelectedItemsProperty,
                                 new Binding(propInfo.Name)
            {
                Mode = BindingMode.TwoWay
            });

            uiElement.GetBindingExpression(CheckedListBox.SelectedItemsProperty).UpdateSource();

            return(uiElement);
        }
コード例 #17
0
        public void Attributes_Cities_UIHintAttribute()
        {
            UIHintAttribute ui = ExpectPropertyAttribute <UIHintAttribute>(typeof(Zip), "FourDigit");

            Assert.AreEqual("DataGrid", ui.UIHint);
            Assert.AreEqual("Jolt", ui.PresentationLayer);
            IDictionary <string, object> controlParams = ui.ControlParameters;

            Assert.IsNotNull(controlParams);
            Assert.AreEqual(2, controlParams.Count);
            Assert.IsTrue(controlParams.ContainsKey("stringParam"));
            Assert.AreEqual("hello", controlParams["stringParam"]);
            Assert.IsTrue(controlParams.ContainsKey("doubleParam"));
            Assert.AreEqual(2.0, controlParams["doubleParam"]);
        }
コード例 #18
0
        public override FrameworkElement Bind(FrameworkElement uiElement, UIHintAttribute uiHint, PropertyInfo propInfo)
        {
            base.Bind(uiElement, uiHint, propInfo);

            uiElement.SetBinding(Selector.SelectedItemProperty,
                                 new Binding(propInfo.Name)
            {
                Mode      = BindingMode.TwoWay,
                Converter = new NullableItemConverter()
            });

            SetComboBoxItemMinHeight((ComboBox)uiElement);

            return(uiElement);
        }
コード例 #19
0
        public void Equals_SameObjectType()
        {
            var a1 = new UIHintAttribute("foo");
            var a2 = new UIHintAttribute("foo");
            var b1 = new UIHintAttribute("foo", "bar");
            var b2 = new UIHintAttribute("foo", "bar");

            Assert.IsTrue(a1.Equals(a2));
            Assert.IsTrue(a2.Equals(a1));

            Assert.IsTrue(b1.Equals(b2));
            Assert.IsTrue(b2.Equals(b1));

            Assert.IsFalse(a1.Equals(b1));
            Assert.IsFalse(b1.Equals(a1));
        }
コード例 #20
0
        public void TemplateHint_AttributesHaveExpectedPrecedence()
        {
            // Arrange
            var expected = "this is a hint";
            var hidden   = new HiddenInputAttribute();
            var uiHint   = new UIHintAttribute(expected);
            var provider = CreateProvider(new object[] { hidden, uiHint, });

            var metadata = provider.GetMetadataForType(typeof(string));

            // Act
            var result = metadata.TemplateHint;

            // Assert
            Assert.Equal(expected, result);
        }
コード例 #21
0
        internal static Chart ProvideChartControl(PropertyInfo propertyInfo, object viewModel,
                                                  UIHintAttribute uiHintAttribute)
        {
            var control = new Chart();

            //check if chart is one series or multi series chart...
            //build seriescontrol for each dataseries


            var independentValuePath =
                (string)uiHintAttribute.ControlParameters[UIHints.ChartControlParameters.ChartCategoryProperty];

            if (independentValuePath == null)
            {
                //try find Category Property
            }


            var dependentValuePath =
                (string)uiHintAttribute.ControlParameters[UIHints.ChartControlParameters.ChartValueProperty];

            if (dependentValuePath == null)
            {
                //try find DisplayChart Value Property
            }


            control.Series.Add(ProvideSeries(propertyInfo, uiHintAttribute, dependentValuePath, independentValuePath));


            control.SetValue(Chart.TitleProperty, propertyInfo.GetDisplayName());

            control.Unloaded += (o, e) =>
            {
                var chart = o as Chart;
                if (chart == null)
                {
                    return;
                }

                BindingOperations.ClearAllBindings(chart);

                chart.Series.Clear();
            };

            return(control);
        }
コード例 #22
0
 public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
 {
     if (context.PropertyAttributes != null)
     {
         foreach (object propAttr in context.PropertyAttributes)
         {
             UIHintAttribute uiHintAttribute = propAttr as UIHintAttribute;
             if (uiHintAttribute != null && uiHintAttribute.ControlParameters != null)
             {
                 foreach (var item in uiHintAttribute.ControlParameters)
                 {
                     context.DisplayMetadata.AdditionalValues.Add(item.Key, item.Value);
                 }
             }
         }
     }
 }
コード例 #23
0
 public void Ctor(string filterUIHint, string presentationLayer, object[] controlParameters, IDictionary<string, object> expectedControlParameters)
 {
     if (controlParameters == null || controlParameters.Length == 0)
     {
         if (presentationLayer == null)
         {
             // Use UIHintAttribute(string)
             UIHintAttribute attribute1 = new UIHintAttribute(filterUIHint);
             VerifyAttribute(attribute1, filterUIHint, presentationLayer, expectedControlParameters);
         }
         // Use UIHintAttribute(string, string)
         UIHintAttribute attribute2 = new UIHintAttribute(filterUIHint, presentationLayer);
         VerifyAttribute(attribute2, filterUIHint, presentationLayer, expectedControlParameters);
     }
     // Use UIHintAttribute(string, string, object[])
     UIHintAttribute attribute3 = new UIHintAttribute(filterUIHint, presentationLayer, controlParameters);
     VerifyAttribute(attribute3, filterUIHint, presentationLayer, expectedControlParameters);
 }
コード例 #24
0
        private static void FindUIHintParameters(Type actionType, FieldInfo field)
        {
            IEnumerable <UIHintAttribute> attributes = CustomAttributeHelpers.GetAttributes <UIHintAttribute>(field);

            using (IEnumerator <UIHintAttribute> enumerator = attributes.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    UIHintAttribute current = enumerator.get_Current();
                    UIHint          hint    = current.get_Hint();
                    UIHint          uIHint  = hint;
                    if (uIHint == 6)
                    {
                        ActionTargets.AddActionTarget(actionType, new ActionTarget(typeof(AnimationClip), field.get_Name(), false));
                    }
                }
            }
        }
コード例 #25
0
        public void Ctor(string filterUIHint, string presentationLayer, object[] controlParameters, IDictionary <string, object> expectedControlParameters)
        {
            if (controlParameters == null || controlParameters.Length == 0)
            {
                if (presentationLayer == null)
                {
                    // Use UIHintAttribute(string)
                    UIHintAttribute attribute1 = new UIHintAttribute(filterUIHint);
                    VerifyAttribute(attribute1, filterUIHint, presentationLayer, expectedControlParameters);
                }
                // Use UIHintAttribute(string, string)
                UIHintAttribute attribute2 = new UIHintAttribute(filterUIHint, presentationLayer);
                VerifyAttribute(attribute2, filterUIHint, presentationLayer, expectedControlParameters);
            }
            // Use UIHintAttribute(string, string, object[])
            UIHintAttribute attribute3 = new UIHintAttribute(filterUIHint, presentationLayer, controlParameters);

            VerifyAttribute(attribute3, filterUIHint, presentationLayer, expectedControlParameters);
        }
コード例 #26
0
        string CheckUIHintAttribute()
        {
            if (uiHintReflected)
            {
                return(uiHint);
            }

            uiHintReflected = true;
            UIHintAttribute attr = null;

            MetaModel.GetDataFieldAttribute <UIHintAttribute> (Attributes, ref attr);

            if (attr == null)
            {
                return(null);
            }

            return(attr.UIHint);
        }
        private void CacheAttributes(Attribute[] attributes)
        {
            DataType      = attributes.OfType <DataTypeAttribute>().FirstOrDefault();
            Display       = attributes.OfType <DisplayAttribute>().FirstOrDefault();
            DisplayColumn = attributes.OfType <DisplayColumnAttribute>().FirstOrDefault();
            DisplayFormat = attributes.OfType <DisplayFormatAttribute>().FirstOrDefault();
            DisplayName   = attributes.OfType <DisplayNameAttribute>().FirstOrDefault();
            Editable      = attributes.OfType <EditableAttribute>().FirstOrDefault();
#if false
            HiddenInput = attributes.OfType <HiddenInputAttribute>().FirstOrDefault();
#endif
            ReadOnly       = attributes.OfType <ReadOnlyAttribute>().FirstOrDefault();
            Required       = attributes.OfType <RequiredAttribute>().FirstOrDefault();
            ScaffoldColumn = attributes.OfType <ScaffoldColumnAttribute>().FirstOrDefault();

            var uiHintAttributes = attributes.OfType <UIHintAttribute>();

            // Developer note: this loop is explicitly unrolled because Linq lambdas methods are not
            // [SecuritySafeCritical] and generate security exceptions accessing DataAnnotations types.
            UIHintAttribute bestUIHint = null;
            foreach (UIHintAttribute uiHintAttribute in uiHintAttributes)
            {
                string presentationLayer = uiHintAttribute.PresentationLayer;
                if (String.Equals(presentationLayer, "MVC", StringComparison.OrdinalIgnoreCase))
                {
                    bestUIHint = uiHintAttribute;
                    break;
                }

                if (bestUIHint == null && String.IsNullOrEmpty(presentationLayer))
                {
                    bestUIHint = uiHintAttribute;
                }
            }

            UIHint = bestUIHint;

            if (DisplayFormat == null && DataType != null)
            {
                DisplayFormat = DataType.DisplayFormat;
            }
        }
コード例 #28
0
        public void UIHintAttribute_Simple_Ctors_Set_Properties() {
            var attr = new UIHintAttribute(null, null);
            Assert.IsNull(attr.UIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute(string.Empty, string.Empty);
            Assert.AreEqual(string.Empty, attr.UIHint);
            Assert.AreEqual(string.Empty, attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute("theHint");
            Assert.AreEqual("theHint", attr.UIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute("theHint", "theLayer");
            Assert.AreEqual("theHint", attr.UIHint);
            Assert.AreEqual("theLayer", attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);
        }
コード例 #29
0
        public virtual FrameworkElement Bind(FrameworkElement uiElement, UIHintAttribute uiHint, PropertyInfo propInfo)
        {
            var controlParameters = uiHint.ControlParameters;

            foreach (var controlParameter in controlParameters)
            {
                uiElement.GetType()
                .GetProperty(controlParameter.Key)
                ?.SetValue(uiElement, controlParameter.Value, null);
            }

            foreach (var controlParameter in
                     new ControlParameterBinder(controlParameters, uiElement)
                     .Bind()
                     .Where(controlParameter => controlParameter.Value != null))
            {
                uiElement.SetBinding(controlParameter.Key, controlParameter.Value);
            }

            return(uiElement);
        }
コード例 #30
0
        public void UIHintAttribute_Simple_Ctors_Set_Properties()
        {
            var attr = new UIHintAttribute(null, null);

            Assert.IsNull(attr.UIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute(string.Empty, string.Empty);
            Assert.AreEqual(string.Empty, attr.UIHint);
            Assert.AreEqual(string.Empty, attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute("theHint");
            Assert.AreEqual("theHint", attr.UIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute("theHint", "theLayer");
            Assert.AreEqual("theHint", attr.UIHint);
            Assert.AreEqual("theLayer", attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);
        }
コード例 #31
0
        private static ISeries ProvideSeries(PropertyInfo propertyInfo, UIHintAttribute uiHintAttribute,
                                             string dependentValuePath, string independentValuePath)
        {
            string chartType = string.Empty;

            if (uiHintAttribute.ControlParameters.ContainsKey(UIHints.ChartControlParameters.ChartType))
            {
                chartType = (string)uiHintAttribute.ControlParameters[UIHints.ChartControlParameters.ChartType];
            }


            switch (chartType)
            {
            case UIHints.ChartControlParameters.ChartTypeArea:
                return(ProvideAreaSeries(propertyInfo, dependentValuePath, independentValuePath));


            case UIHints.ChartControlParameters.ChartTypeBar:
                return(ProvideBarSeries(propertyInfo, dependentValuePath, independentValuePath));

            case UIHints.ChartControlParameters.ChartTypeBubble:
                return(ProvideBubbleSeries(propertyInfo, dependentValuePath, independentValuePath));

            case UIHints.ChartControlParameters.ChartTypeLine:
                return(ProvideLineSeries(propertyInfo, dependentValuePath, independentValuePath));

            case UIHints.ChartControlParameters.ChartTypePie:
                return(ProvidePieSeries(propertyInfo, dependentValuePath, independentValuePath));

            case UIHints.ChartControlParameters.ChartTypeScatter:
                return(ProvideScatterSeries(propertyInfo, dependentValuePath, independentValuePath));

            default:
                return(ProvideAreaSeries(propertyInfo, dependentValuePath, independentValuePath));
            }
        }
コード例 #32
0
 public void Equals(UIHintAttribute attribute, object obj, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(obj));
     Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode());
 }
コード例 #33
0
 public void ConstructorControlParameters_UnevenNumber() {
     var attr = new UIHintAttribute("", "", "");
     ExceptionHelper.ExpectException<InvalidOperationException>(delegate() {
         var v = attr.ControlParameters;
     }, Resources.DataAnnotationsResources.UIHintImplementation_NeedEvenNumberOfControlParameters);
 }
コード例 #34
0
 public virtual FrameworkElement Bind(FrameworkElement uiElement, UIHintAttribute uiHint, PropertyInfo propInfo)
 {
     return(_generator?.Bind(uiElement, uiHint, propInfo));
 }
コード例 #35
0
        public void Equals_DoesNotThrow() {
            var a1 = new UIHintAttribute("foo", "bar");
            var a2 = new UIHintAttribute("foo", "bar", 1);

            Assert.IsFalse(a1.Equals(a2));
            Assert.IsFalse(a2.Equals(a1));
        }
コード例 #36
0
 public void ConstructorControlParameters_DuplicateKey() {
     var attr = new UIHintAttribute("", "", "key", "value1", "key", "value2");
     ExceptionHelper.ExpectException<InvalidOperationException>(delegate() {
         var v = attr.ControlParameters;
     }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.UIHintImplementation_ControlParameterKeyOccursMoreThanOnce, 2, "key"));
 }
コード例 #37
0
        public void Equals_SameObjectType() {
            var a1 = new UIHintAttribute("foo");
            var a2 = new UIHintAttribute("foo");
            var b1 = new UIHintAttribute("foo", "bar");
            var b2 = new UIHintAttribute("foo", "bar");

            Assert.IsTrue(a1.Equals(a2));
            Assert.IsTrue(a2.Equals(a1));

            Assert.IsTrue(b1.Equals(b2));
            Assert.IsTrue(b2.Equals(b1));

            Assert.IsFalse(a1.Equals(b1));
            Assert.IsFalse(b1.Equals(a1));
        }
コード例 #38
0
 public void InvalidControlParameters_Get_ThrowsInvalidOperationException(object[] controlParameters)
 {
     UIHintAttribute attribute = new UIHintAttribute("FilterUIHint", "PresentationLayer", controlParameters);
     Assert.Throws<InvalidOperationException>(() => attribute.ControlParameters);
 }
コード例 #39
0
        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.GetDataTypeName();
            }

            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;
                }
            }

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

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

            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);
        }
コード例 #40
0
        public void Equals_SameObjectType_WithParamsDictionary() {
            var a1 = new UIHintAttribute("foo", "bar", "a", 1, "b", false);
            var a2 = new UIHintAttribute("foo", "bar", "b", false, "a", 1);

            Assert.IsTrue(a1.Equals(a2));
            Assert.IsTrue(a2.Equals(a1));
        }
コード例 #41
0
 public void ConstructorControlParameters_NullKey() {
     var attr = new UIHintAttribute("", "", null, "value");
     ExceptionHelper.ExpectException<InvalidOperationException>(delegate() {
         var v = attr.ControlParameters;
     }, String.Format(CultureInfo.CurrentCulture, Resources.DataAnnotationsResources.UIHintImplementation_ControlParameterKeyIsNull, 0));
 }