Example #1
0
        /// <summary>
        /// Constructeur.
        /// </summary>
        public BeanDynamic()
        {
            PropertyDescriptor[] propertyArray = new PropertyDescriptor[4];

            DataMemberAttribute memberAttribute = new DataMemberAttribute();

            memberAttribute.IsRequired = true;
            RequiredAttribute          requiredAttribute    = new RequiredAttribute();
            ColumnAttribute            columnAttribute      = new ColumnAttribute("BEA_ID");
            KeyAttribute               keyAttribute         = new KeyAttribute();
            DatabaseGeneratedAttribute dbGenAttr            = new DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity);
            ReferencedTypeAttribute    associationAttribute = new ReferencedTypeAttribute(typeof(Bean));
            DomainAttribute            domainAttribute      = new DomainAttribute("IDENTIFIANT");

            propertyArray[0] = new DynamicPropertyDescriptor("Id", typeof(int?),
                                                             new Attribute[] { associationAttribute, memberAttribute, domainAttribute, columnAttribute, requiredAttribute, keyAttribute, dbGenAttr });

            memberAttribute  = new DataMemberAttribute();
            columnAttribute  = new ColumnAttribute("OTH_ID");
            domainAttribute  = new DomainAttribute("IDENTIFIANT");
            propertyArray[1] = new DynamicPropertyDescriptor("OtherId", typeof(int?),
                                                             new Attribute[] { domainAttribute, memberAttribute, columnAttribute });

            propertyArray[2] = new DynamicPropertyDescriptor("Libelle", typeof(string), new Attribute[] { });

            propertyArray[3] = new DynamicPropertyDescriptor("DateCreation", typeof(DateTime?), new Attribute[] { });

            _propertyDescriptors = new PropertyDescriptorCollection(propertyArray);
        }
            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                DynamicPropertyDescriptor _context
                    = context.PropertyDescriptor as DynamicPropertyDescriptor;

                return(new StandardValuesCollection(_context.GetPropertyObject().GetOptions()));
            }
        /// <summary>
        /// Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="value">An <see cref="T:System.Object"/> that specifies the type of array for which to get properties.</param>
        /// <param name="attributes">An array of type <see cref="T:System.Attribute"/> that is used as a filter.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"/> with the properties that are exposed for this data type, or null if there are no properties.
        /// </returns>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            // Fill collection with properties descriptors
            PropertyDescriptorCollection propDescriptors = TypeDescriptor.GetProperties(value, attributes, false);

            // Return original collection if not in design mode
            if (context != null && context.Instance is ChartElement &&
                (context.Instance as ChartElement).Chart != null &&
                (context.Instance as ChartElement).Chart.IsDesignMode())
            {
                // Create new descriptors collection
                PropertyDescriptorCollection newPropDescriptors = new PropertyDescriptorCollection(null);

                // Loop through all original property descriptors
                foreach (PropertyDescriptor propertyDescriptor in propDescriptors)
                {
                    // Change name of "CustomAttributesEx" property to "CustomProperties"
                    if (propertyDescriptor.Name == "CustomAttributesEx")
                    {
                        DynamicPropertyDescriptor dynPropDesc = new DynamicPropertyDescriptor(
                            propertyDescriptor,
                            "CustomProperties");
                        newPropDescriptors.Add(dynPropDesc);
                    }
                    else
                    {
                        newPropDescriptors.Add(propertyDescriptor);
                    }
                }
                return(newPropDescriptors);
            }

            // Return original collection if not in design mode
            return(propDescriptors);
        }
 public void Compare_XHasAPropertyOrderButYDoesNot_XComesFirst()
 {
     DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
     DynamicPropertyDescriptor x = new DynamicPropertyDescriptor(new MockPropertyDescriptor("X")).SetPropertyOrder(1);
     DynamicPropertyDescriptor y = new DynamicPropertyDescriptor(new MockPropertyDescriptor("Y")).SetPropertyOrder(null);
     int result = comparer.Compare(x, y);
     Assert.That(result, Is.LessThan(0));
 }
 public void Compare_NeitherValueHasAPropertyOrderButYComesFirstAlphabetically_YComesFirst()
 {
     DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
     DynamicPropertyDescriptor x = new DynamicPropertyDescriptor(new MockPropertyDescriptor("1"));
     DynamicPropertyDescriptor y = new DynamicPropertyDescriptor(new MockPropertyDescriptor("0"));
     int result = comparer.Compare(x, y);
     Assert.That(result, Is.GreaterThan(0));
 }
 public void Compare_BothHaveEqualPropertyOrderButXComesFirstAlphabetically_XComesFirst()
 {
     DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
     DynamicPropertyDescriptor x = new DynamicPropertyDescriptor(new MockPropertyDescriptor("0")).SetPropertyOrder(0);
     DynamicPropertyDescriptor y = new DynamicPropertyDescriptor(new MockPropertyDescriptor("1")).SetPropertyOrder(0);
     int result = comparer.Compare(x, y);
     Assert.That(result, Is.LessThan(0));
 }
 public void Compare_BothHaveAPropertyOrderButYComesFirst_YComesFirst()
 {
     DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
     DynamicPropertyDescriptor x = new DynamicPropertyDescriptor(new MockPropertyDescriptor("X")).SetPropertyOrder(1);
     DynamicPropertyDescriptor y = new DynamicPropertyDescriptor(new MockPropertyDescriptor("Y")).SetPropertyOrder(0);
     int result = comparer.Compare(x, y);
     Assert.That(result, Is.GreaterThan(0));
 }
        public void Compare_BothHaveEqualPropertyOrderButYComesFirstAlphabetically_YComesFirst()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("1")).SetPropertyOrder(0);
            DynamicPropertyDescriptor         y        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("0")).SetPropertyOrder(0);
            int result = comparer.Compare(x, y);

            result.Should().BeGreaterThan(0);
        }
        public void Compare_XIsNullAndYIsNot_YComesFirst()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = null;
            DynamicPropertyDescriptor         y        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("Y"));
            int result = comparer.Compare(x, y);

            result.Should().BeGreaterThan(0);
        }
        public void Compare_BothHaveAPropertyOrderButYComesFirst_YComesFirst()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("X")).SetPropertyOrder(1);
            DynamicPropertyDescriptor         y        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("Y")).SetPropertyOrder(0);
            int result = comparer.Compare(x, y);

            result.Should().BeGreaterThan(0);
        }
        public void Compare_XHasAPropertyOrderButYDoesNot_XComesFirst()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("X")).SetPropertyOrder(1);
            DynamicPropertyDescriptor         y        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("Y")).SetPropertyOrder(null);
            int result = comparer.Compare(x, y);

            result.Should().BeLessThan(0);
        }
        public void Compare_BothXAndYAreNull_ValuesAreEqual()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = null;
            DynamicPropertyDescriptor         y        = null;
            int result = comparer.Compare(x, y);

            result.Should().Be(0);
        }
        public void Category_NoOverride_ReturnsDescriptorValue()
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.CategoryResult = "Base";

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            Assert.That(dynamicDescriptor.Category, Is.EqualTo("Base"));
        }
        public void Compare_NeitherValueHasAPropertyOrderButXComesFirstAlphabetically_XComesFirst()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("0"));
            DynamicPropertyDescriptor         y        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("1"));
            int result = comparer.Compare(x, y);

            result.Should().BeLessThan(0);
        }
        public void ComponentType_ReturnsResultOfDescriptorComponentType()
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            Type type = typeof(string);
            mockDescriptor.ComponentTypeResult = type;
            Assert.That(dynamicDescriptor.ComponentType, Is.EqualTo(type));
        }
        public void Compare_YIsNullAndXIsNot_XComesFirst()
        {
            DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
            DynamicPropertyDescriptor         x        = new DynamicPropertyDescriptor(new MockPropertyDescriptor("X"));
            DynamicPropertyDescriptor         y        = null;
            int result = comparer.Compare(x, y);

            result.Should().BeLessThan(0);
        }
Example #17
0
        public void IsReadOnly_NoOverride_ReturnsDescriptorValue(bool value)
        {
            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.IsReadOnlyResult = value;

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.IsReadOnly.Should().Be(value);
        }
Example #18
0
        public void DisplayName_NoOverride_ReturnsDescriptorValue()
        {
            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.DisplayNameResult = "Base";

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.DisplayName.Should().Be("Base");
        }
Example #19
0
        public void PropertyType_ReturnsResultOfDescriptorPropertyType()
        {
            var mockDescriptor    = new MockPropertyDescriptor();
            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            var type = typeof(string);

            mockDescriptor.PropertyTypeResult = type;
            dynamicDescriptor.PropertyType.Should().Be(type);
        }
Example #20
0
        public void Category_NoOverride_ReturnsDescriptorValue()
        {
            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.CategoryResult = "Base";

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.Category.Should().Be("Base");
        }
        public void Converter_NoOverride_ReturnsDescriptorValue()
        {
            TypeConverter converter = new TypeConverter();

            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.ConverterResult = converter;

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            Assert.That(dynamicDescriptor.Converter, Is.EqualTo(converter));
        }
Example #22
0
        public void ResetValue_CallsDescriptorResetValue()
        {
            var mockDescriptor    = new MockPropertyDescriptor();
            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            var component = new object();

            dynamicDescriptor.ResetValue(component);
            mockDescriptor.ResetValueComponent.Should().Be(component);
            mockDescriptor.ResetValueCalled.Should().BeTrue();
        }
Example #23
0
        public static DynamicTypeDescriptor GetTypeDescriptor(ISysObjectManager mgr, Type type,
                                                              IEnumerable <SysObject> items)
        {
            var res = new DynamicTypeDescriptor(type);

            foreach (var o in items)
            {
                // разбор
                var attributes = GetAttributes(o, type);

                // описание типа
                var sysObjNameAttr =
                    Attribute.GetCustomAttribute(type, typeof(SysObjectNameAttribute)) as SysObjectNameAttribute;
                var typename = sysObjNameAttr != null
                    ? sysObjNameAttr.SysObjectName
                    : type.Name;

                if (typename.EqIgnoreCase(o.ObjectName))
                {
                    //TODO: правильнее было бы передавать все аттрибуты
                    res.AddAttributes(
                        attributes.Where(p => p is DisplayNameAttribute || p is ListViewCaptionAttribute).ToArray());
                    continue;
                }

                var propertyType = GetObjectTrueType(mgr, o);

                //HACK: Добавляем атрибут CustomXmlIgnoreAttribute к свойству
                if (typeof(IList).IsAssignableFrom(propertyType) && propertyType.IsGenericType)
                {
                    var itemType = propertyType.GetGenericArguments().FirstOrDefault();
                    if (
                        itemType != null && (
                            typeof(AddressBook) == itemType ||
                            typeof(IWBPosQLFDetailDesc) == itemType ||
                            typeof(GlobalParamValue).IsAssignableFrom(itemType) ||
                            typeof(EpsConfig).IsAssignableFrom(itemType)) ||
                        typeof(MotionAreaGroupTr).IsAssignableFrom(itemType)
                        )
                    {
                        var attrs = new List <Attribute>(attributes)
                        {
                            new XmlNotIgnoreAttribute()
                        };
                        attributes = attrs.ToArray();
                    }
                }

                var propertyDesc = new DynamicPropertyDescriptor(o.ObjectName, attributes, type, propertyType,
                                                                 o.ObjectDefaultValue);
                res.AddProperty(propertyDesc);
            }
            return(res);
        }
Example #24
0
        public void Converter_NoOverride_ReturnsDescriptorValue()
        {
            var converter = new TypeConverter();

            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.ConverterResult = converter;

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.Converter.Should().Be(converter);
        }
Example #25
0
        public void Description_Override_ReturnsOverrideValue()
        {
            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.DescriptionResult = "Base";

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.SetDescription("Override");

            dynamicDescriptor.Description.Should().Be("Override");
        }
Example #26
0
        public void IsReadOnly_Override_ReturnsOverrideValue(bool descriptorValue, bool overrideValue)
        {
            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.IsReadOnlyResult = descriptorValue;

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.SetReadOnly(overrideValue);

            dynamicDescriptor.IsReadOnly.Should().Be(overrideValue);
        }
Example #27
0
        public void GetEditor_NoOverride_ReturnsDescriptorValue()
        {
            var baseEditor = new MockUITypeEditor();

            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.GetEditorResult = baseEditor;

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.GetEditor(typeof(MockUITypeEditor)).Should().Be(baseEditor);
        }
Example #28
0
        public void GetValue_ReturnsResultOfDescriptorGetValue()
        {
            var mockDescriptor    = new MockPropertyDescriptor();
            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            var component = new object();
            var result    = new object();

            mockDescriptor.GetValueResult = result;
            dynamicDescriptor.GetValue(component).Should().Be(result);
            mockDescriptor.GetValueComponent.Should().Be(component);
        }
Example #29
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            var propertyDescriptor = context.PropertyDescriptor;

            var properties = new PropertyDescriptor[4];

            properties[0] = new DynamicPropertyDescriptor("Val0", typeof(double), c => ((Scalar)c).Val0, (c, v) => { var s = (Scalar)c; s.Val0 = (double)v; propertyDescriptor.SetValue(context.Instance, s); });
            properties[1] = new DynamicPropertyDescriptor("Val1", typeof(double), c => ((Scalar)c).Val1, (c, v) => { var s = (Scalar)c; s.Val1 = (double)v; propertyDescriptor.SetValue(context.Instance, s); });
            properties[2] = new DynamicPropertyDescriptor("Val2", typeof(double), c => ((Scalar)c).Val2, (c, v) => { var s = (Scalar)c; s.Val2 = (double)v; propertyDescriptor.SetValue(context.Instance, s); });
            properties[3] = new DynamicPropertyDescriptor("Val3", typeof(double), c => ((Scalar)c).Val3, (c, v) => { var s = (Scalar)c; s.Val3 = (double)v; propertyDescriptor.SetValue(context.Instance, s); });

            return(new PropertyDescriptorCollection(properties));
        }
Example #30
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            var propertyDescriptor = context.PropertyDescriptor;
            var hueAttributes      = new Attribute[] { new RangeAttribute(0, 179), new EditorAttribute(DesignTypes.SliderEditor, DesignTypes.UITypeEditor) };
            var satValAttributes   = new Attribute[] { new RangeAttribute(0, 255), new EditorAttribute(DesignTypes.SliderEditor, DesignTypes.UITypeEditor) };

            var properties = new PropertyDescriptor[3];

            properties[0] = new DynamicPropertyDescriptor("H", typeof(double), c => ((Scalar)c).Val0, (c, v) => { var s = (Scalar)c; s.Val0 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, hueAttributes);
            properties[1] = new DynamicPropertyDescriptor("S", typeof(double), c => ((Scalar)c).Val1, (c, v) => { var s = (Scalar)c; s.Val1 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, satValAttributes);
            properties[2] = new DynamicPropertyDescriptor("V", typeof(double), c => ((Scalar)c).Val2, (c, v) => { var s = (Scalar)c; s.Val2 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, satValAttributes);

            return(new PropertyDescriptorCollection(properties));
        }
Example #31
0
        public void Converter_Override_ReturnsOverrideValue()
        {
            var converterBase     = new TypeConverter();
            var converterOverride = new TypeConverter();

            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.ConverterResult = converterBase;

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.SetConverter(converterOverride);

            dynamicDescriptor.Converter.Should().Be(converterOverride);
        }
        public void CanResetValue_ReturnsResultOfDescriptorCanResetValue()
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            object component = new object();

            mockDescriptor.CanResetValueResult = true;
            Assert.That(dynamicDescriptor.CanResetValue(component), Is.True);
            Assert.That(mockDescriptor.CanResetValueComponent, Is.EqualTo(component));

            mockDescriptor.CanResetValueResult = false;
            Assert.That(dynamicDescriptor.CanResetValue(component), Is.False);
            Assert.That(mockDescriptor.CanResetValueComponent, Is.EqualTo(component));
        }
Example #33
0
        public void CanResetValue_ReturnsResultOfDescriptorCanResetValue()
        {
            var mockDescriptor    = new MockPropertyDescriptor();
            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            var component = new object();

            mockDescriptor.CanResetValueResult = true;
            dynamicDescriptor.CanResetValue(component).Should().BeTrue();
            mockDescriptor.CanResetValueComponent.Should().Be(component);

            mockDescriptor.CanResetValueResult = false;
            dynamicDescriptor.CanResetValue(component).Should().BeFalse();
            mockDescriptor.CanResetValueComponent.Should().Be(component);
        }
Example #34
0
        private static string GetAttrEntityItemValue(DynamicPropertyDescriptor desc)
        {
            if (typeof(ICollection).IsAssignableFrom(desc.PropertyType))
            {
                var itemType = desc.PropertyType.GetCollectionElementType();
                if (itemType == null)
                {
                    throw new DeveloperException("Can't get element type from collection with type " + desc.PropertyType);
                }

                var innerAttrEntity = GetAttrEntity(itemType);
                return(string.Format("<{0}>{1}</{0}>", desc.SourceName, innerAttrEntity));
            }

            return(string.Format("<{0} />", desc.SourceName));
        }
Example #35
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            var propertyDescriptor = context.PropertyDescriptor;
            var editorAttribute    = propertyDescriptor.Attributes[typeof(EditorAttribute)] ?? new EditorAttribute(DesignTypes.NumericUpDownEditor, DesignTypes.UITypeEditor);
            var valueAttributes    = new Attribute[] { propertyDescriptor.Attributes[typeof(PrecisionAttribute)], propertyDescriptor.Attributes[typeof(RangeAttribute)], editorAttribute };

            var properties = new PropertyDescriptor[4];

            properties[0] = new DynamicPropertyDescriptor("B", typeof(double), c => ((Scalar)c).Val0, (c, v) => { var s = (Scalar)c; s.Val0 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, valueAttributes);
            properties[1] = new DynamicPropertyDescriptor("G", typeof(double), c => ((Scalar)c).Val1, (c, v) => { var s = (Scalar)c; s.Val1 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, valueAttributes);
            properties[2] = new DynamicPropertyDescriptor("R", typeof(double), c => ((Scalar)c).Val2, (c, v) => { var s = (Scalar)c; s.Val2 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, valueAttributes);
            properties[3] = new DynamicPropertyDescriptor("A", typeof(double), c => ((Scalar)c).Val3, (c, v) => { var s = (Scalar)c; s.Val3 = (double)v; propertyDescriptor.SetValue(context.Instance, s); }, valueAttributes);

            var names = new[] { "B", "G", "R", "A" };

            return(new PropertyDescriptorCollection(properties).Sort(names));
        }
Example #36
0
        public void GetEditor_MultipleOverrides_ReturnsMostRecentOverrideValue()
        {
            var baseEditor      = new MockUITypeEditor();
            var overrideEditor1 = new MockUITypeEditor();
            var overrideEditor2 = new MockUITypeEditor();

            var mockDescriptor = new MockPropertyDescriptor();

            mockDescriptor.GetEditorResult = baseEditor;

            var dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            dynamicDescriptor.SetEditor(typeof(MockUITypeEditor), overrideEditor1);
            dynamicDescriptor.SetEditor(typeof(MockUITypeEditor), overrideEditor2);

            dynamicDescriptor.GetEditor(typeof(MockUITypeEditor)).Should().Be(overrideEditor2);
        }
            public override object ConvertFrom(ITypeDescriptorContext context,
                                               System.Globalization.CultureInfo culture,
                                               object value)
            {
                //convert to string
                DynamicPropertyDescriptor _context
                    = context.PropertyDescriptor as DynamicPropertyDescriptor;

                if (_context.GetPropertyObject().Value.GetType()
                    != value.GetType())
                {
                    //convert to string;
                    return(value.ToString());
                }
                else
                {
                    return(base.ConvertFrom(context, culture, value));
                }
            }
Example #38
0
 public CheckLeaf(string Name, CheckTree Parent, DynamicPropertyDescriptor<bool> Property)
     : base(Name, Parent)
 {
     Property_ = Property;
 }
        public void DisplayName_Override_ReturnsOverrideValue()
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.DisplayNameResult = "Base";

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);
            dynamicDescriptor.SetDisplayName("Override");

            Assert.That(dynamicDescriptor.DisplayName, Is.EqualTo("Override"));
        }
        public void GetEditor_Override_ReturnsOverrideValue()
        {
            MockUITypeEditor baseEditor = new MockUITypeEditor();
            MockUITypeEditor overrideEditor = new MockUITypeEditor();

            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.GetEditorResult = baseEditor;

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);
            dynamicDescriptor.SetEditor(typeof(MockUITypeEditor), overrideEditor);

            Assert.That(dynamicDescriptor.GetEditor(typeof(MockUITypeEditor)), Is.EqualTo(overrideEditor));
        }
        public void IsReadOnly_NoOverride_ReturnsDescriptorValue(bool value)
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.IsReadOnlyResult = value;

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            Assert.That(dynamicDescriptor.IsReadOnly, Is.EqualTo(value));
        }
        public void GetValue_ReturnsResultOfDescriptorGetValue()
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            object component = new object();
            object result = new object();

            mockDescriptor.GetValueResult = result;
            Assert.That(dynamicDescriptor.GetValue(component), Is.EqualTo(result));
            Assert.That(mockDescriptor.GetValueComponent, Is.EqualTo(component));
        }
 protected override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
 {
     PropertyDescriptorCollection descriptors = base.GetProperties(attributes);
     PropertyDescriptor dataSourceDescriptor = descriptors.Find("DataSource", true);
     if (dataSourceDescriptor != null)
     {
         int index = descriptors.IndexOf(dataSourceDescriptor);
         PropertyDescriptor[] descriptorArray = new PropertyDescriptor[descriptors.Count];
         descriptors.CopyTo(descriptorArray, 0);
         descriptorArray[index] = new DynamicPropertyDescriptor(dataSourceDescriptor, new TypeConverterAttribute(typeof(DataSourceConverter)));
         (descriptorArray[index] as DynamicPropertyDescriptor).CanResetValueHandler = new CanResetValueHandler(CanResetDataSource);
         (descriptorArray[index] as DynamicPropertyDescriptor).ResetValueHandler = new ResetValueHandler(ResetDataSource);
         descriptors = new PropertyDescriptorCollection(descriptorArray, true);
     }
     return descriptors;
 }
 public void Compare_YIsNullAndXIsNot_XComesFirst()
 {
     DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
     DynamicPropertyDescriptor x = new DynamicPropertyDescriptor(new MockPropertyDescriptor("X"));
     DynamicPropertyDescriptor y = null;
     int result = comparer.Compare(x, y);
     Assert.That(result, Is.LessThan(0));
 }
        public void SetValue_CallsDescriptorSetValue()
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);

            object component = new object();
            object value = new object();
            dynamicDescriptor.SetValue(component, value);
            Assert.That(mockDescriptor.SetValueComponent, Is.EqualTo(component));
            Assert.That(mockDescriptor.SetValueValue, Is.EqualTo(value));
            Assert.That(mockDescriptor.SetValueCalled, Is.True);
        }
 public void Compare_XIsNullAndYIsNot_YComesFirst()
 {
     DynamicPropertyDescriptorComparer comparer = new DynamicPropertyDescriptorComparer();
     DynamicPropertyDescriptor x = null;
     DynamicPropertyDescriptor y = new DynamicPropertyDescriptor(new MockPropertyDescriptor("Y"));
     int result = comparer.Compare(x, y);
     Assert.That(result, Is.GreaterThan(0));
 }
        public void Converter_Override_ReturnsOverrideValue()
        {
            TypeConverter converterBase = new TypeConverter();
            TypeConverter converterOverride = new TypeConverter();

            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.ConverterResult = converterBase;

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);
            dynamicDescriptor.SetConverter(converterOverride);

            Assert.That(dynamicDescriptor.Converter, Is.EqualTo(converterOverride));
        }
Example #48
0
 private void AddLeaf(string Name, DynamicPropertyDescriptor<bool> Property)
 {
     Children_[Name] = new CheckLeaf(Name, this, Property);
 }
        public void IsReadOnly_Override_ReturnsOverrideValue(bool descriptorValue, bool overrideValue)
        {
            MockPropertyDescriptor mockDescriptor = new MockPropertyDescriptor();
            mockDescriptor.IsReadOnlyResult = descriptorValue;

            DynamicPropertyDescriptor dynamicDescriptor = new DynamicPropertyDescriptor(mockDescriptor);
            dynamicDescriptor.SetReadOnly(overrideValue);

            Assert.That(dynamicDescriptor.IsReadOnly, Is.EqualTo(overrideValue));
        }