Ejemplo n.º 1
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            // Rather than passing this function on to the default TypeDescriptor,
            // which would return the actual properties of PropertyBag, I construct
            // a list here that contains property descriptors for the elements of the
            // Properties list in the bag.

            ArrayList props = new ArrayList();

            foreach (PropertySpec property in properties)
            {
                ArrayList attrs = new ArrayList();

                // If a category, description, editor, or type converter are specified
                // in the PropertySpec, create attributes to define that relationship.
                if (property.Category != null)
                {
                    attrs.Add(new CategoryAttribute(property.Category));
                }

                if (property.Description != null)
                {
                    attrs.Add(new DescriptionAttribute(property.Description));
                }

                if (property.EditorTypeName != null)
                {
                    attrs.Add(new EditorAttribute(property.EditorTypeName, typeof(UITypeEditor)));
                }

                if (property.ConverterTypeName != null)
                {
                    attrs.Add(new TypeConverterAttribute(property.ConverterTypeName));
                }

                // Additionally, append the custom attributes associated with the
                // PropertySpec, if any.
                if (property.Attributes != null)
                {
                    attrs.AddRange(property.Attributes);
                }

                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create a new property descriptor for the property item, and add
                // it to the list.
                PropertySpecDescriptor pd = new PropertySpecDescriptor(property,
                                                                       this, property.Name, attrArray);
                props.Add(pd);
            }

            // Convert the list of PropertyDescriptors to a collection that the
            // ICustomTypeDescriptor can use, and return it.
            PropertyDescriptor[] propArray = (PropertyDescriptor[])props.ToArray(
                typeof(PropertyDescriptor));
            return(new PropertyDescriptorCollection(propArray));
        }
Ejemplo n.º 2
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection result = TypeDescriptor.GetProperties(this, attributes, true);

            List <PropertyDescriptor> props = new List <PropertyDescriptor>(result.Count);

            foreach (PropertyDescriptor item in result)
            {
                props.Add(item);
            }

            if (objdef.CustomProperties != null)
            {
                foreach (PropertySpec property in objdef.CustomProperties)
                {
                    List <Attribute> attrs = new List <Attribute>();

                    // Additionally, append the custom attributes associated with the
                    // PropertySpec, if any.
                    if (property.Attributes != null)
                    {
                        attrs.AddRange(property.Attributes);
                    }

                    // Create a new property descriptor for the property item, and add
                    // it to the list.
                    PropertySpecDescriptor pd = new PropertySpecDescriptor(property,
                                                                           property.Name, attrs.ToArray());
                    props.Add(pd);
                }
            }

            if (this is MissionSETItem && objdef.MissionProperties != null)
            {
                foreach (PropertySpec property in objdef.MissionProperties)
                {
                    List <Attribute> attrs = new List <Attribute>();

                    // Additionally, append the custom attributes associated with the
                    // PropertySpec, if any.
                    if (property.Attributes != null)
                    {
                        attrs.AddRange(property.Attributes);
                    }

                    // Create a new property descriptor for the property item, and add
                    // it to the list.
                    PropertySpecDescriptor pd = new PropertySpecDescriptor(property,
                                                                           property.Name, attrs.ToArray());
                    props.Add(pd);
                }
            }

            return(new PropertyDescriptorCollection(props.ToArray(), true));
        }
Ejemplo n.º 3
0
        public void IsBrowsable_PropertyHasBrowsableFalseAttribute_ReturnFalse()
        {
            // Setup
            var instance   = new ClassWithProperties();
            var spec       = new PropertySpec(instance.GetType().GetProperty("PropertyWithBrowsableFalseAttribute"));
            var descriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            bool isBrowsable = descriptor.IsBrowsable;

            // Assert
            Assert.IsFalse(isBrowsable);
        }
Ejemplo n.º 4
0
        public void CanResetValue_ReturnFalse()
        {
            // Setup
            var instance           = new ClassWithProperties();
            var spec               = new PropertySpec(instance.GetType().GetProperty("PropertyWithOnlyGetter"));
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            bool canReset = propertyDescriptor.CanResetValue(instance);

            // Assert
            Assert.IsFalse(canReset);
        }
Ejemplo n.º 5
0
        public void GetValue_SimpleValueProperty_ReturnPropertyValue()
        {
            // Setup
            var instance           = new ClassWithProperties();
            var spec               = new PropertySpec(instance.GetType().GetProperty("PropertyWithOnlyGetter"));
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            object value = propertyDescriptor.GetValue(instance);

            // Assert
            Assert.AreEqual(instance.PropertyWithOnlyGetter, value);
        }
Ejemplo n.º 6
0
        public void GetValue_ObjectValueProperty_ReturnPropertyValue()
        {
            // Setup
            var instance           = new ClassWithProperties();
            var spec               = new PropertySpec(instance.GetType().GetProperty("ComplexSubProperty"));
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            object value = propertyDescriptor.GetValue(instance);

            // Assert
            Assert.AreSame(instance.ComplexSubProperty, value);
        }
Ejemplo n.º 7
0
        public void IsReadOnly_PropertyHasReadOnlyFalseAttribute_ReturnFalse()
        {
            // Setup
            var instance   = new ClassWithProperties();
            var spec       = new PropertySpec(instance.GetType().GetProperty("PropertyWithReadOnlyFalseAttribute"));
            var descriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            bool isReadOnly = descriptor.IsReadOnly;

            // Assert
            Assert.IsFalse(isReadOnly);
        }
Ejemplo n.º 8
0
        public void ShouldSerializeValue_ReturnFalse()
        {
            // Setup
            var instance           = new ClassWithProperties();
            var spec               = new PropertySpec(instance.GetType().GetProperty("PropertyWithOnlyGetter"));
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            bool shouldSerializeValue = propertyDescriptor.ShouldSerializeValue(instance);

            // Assert
            Assert.IsFalse(shouldSerializeValue);
        }
Ejemplo n.º 9
0
        public void IsReadOnly_PropertyHasNoAttributeAndOnlyGetter_ReturnTrue()
        {
            // Setup
            var instance   = new ClassWithProperties();
            var spec       = new PropertySpec(instance.GetType().GetProperty("PropertyWithOnlyGetter"));
            var descriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            bool isReadOnly = descriptor.IsReadOnly;

            // Assert
            Assert.IsTrue(isReadOnly);
        }
Ejemplo n.º 10
0
        public void IsReadOnly_PropertyHasDynamicReadOnlyProperty_ReturnExpectedValue(bool isPropertyReadOnly)
        {
            // Setup
            var instance = new ClassWithProperties
            {
                IsPropertyReadOnly = isPropertyReadOnly
            };
            var propertySpec = new PropertySpec(instance.GetType().GetProperty("IntegerPropertyWithDynamicReadOnly"));
            var descriptor   = new PropertySpecDescriptor(propertySpec, instance);

            // Call
            bool isReadOnly = descriptor.IsReadOnly;

            // Assert
            Assert.AreEqual(isPropertyReadOnly, isReadOnly);
        }
Ejemplo n.º 11
0
        public void ParameteredConstructor_IsPropertyReadOnlyProperty_ExpectedValues()
        {
            // Setup
            var          instance     = new ClassWithProperties();
            PropertyInfo propertyInfo = instance.GetType().GetProperty("IsPropertyReadOnly");
            var          spec         = new PropertySpec(propertyInfo);

            // Call
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Assert
            Assert.AreEqual(spec.GetType(), propertyDescriptor.ComponentType);
            Assert.IsFalse(propertyDescriptor.IsReadOnly);
            Assert.IsTrue(propertyDescriptor.IsBrowsable);
            Assert.AreEqual(propertyInfo.PropertyType, propertyDescriptor.PropertyType);
        }
Ejemplo n.º 12
0
        public void GetValue_ObjectValuePropertyWithExpandableObjectConverterAttribute_ReturnPropertyValueWrappedInDynamicPropertyBag()
        {
            // Setup
            var instance           = new ClassWithProperties();
            var spec               = new PropertySpec(instance.GetType().GetProperty("ComplexSubPropertyWithExandableObjectConverter"));
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Call
            object value = propertyDescriptor.GetValue(instance);

            // Assert
            var dynamicPropertyBag = (DynamicPropertyBag)value;

            Assert.IsNotNull(dynamicPropertyBag);
            Assert.AreSame(instance.ComplexSubPropertyWithExandableObjectConverter, dynamicPropertyBag.WrappedObject);
        }
Ejemplo n.º 13
0
        public void ResetValue_CanNotReset_ThrowsInvalidOperationException()
        {
            // Setup
            var instance           = new ClassWithProperties();
            var spec               = new PropertySpec(instance.GetType().GetProperty("PropertyWithOnlyGetter"));
            var propertyDescriptor = new PropertySpecDescriptor(spec, instance);

            // Precondition
            Assert.IsFalse(propertyDescriptor.CanResetValue(instance));

            // Call
            TestDelegate call = () => propertyDescriptor.ResetValue(instance);

            // Assert
            Assert.Throws <InvalidOperationException>(call);
        }
Ejemplo n.º 14
0
        public void IsBrowsable_PropertyHasDynamicBrowsableProperty_ReturnExpectedValue(bool isPropertyVisible)
        {
            // Setup
            var instance = new ClassWithProperties
            {
                IsPropertyBrowsable = isPropertyVisible
            };
            var propertySpec = new PropertySpec(instance.GetType().GetProperty("IntegerPropertyWithDynamicVisibility"));
            var descriptor   = new PropertySpecDescriptor(propertySpec, instance);

            // Call
            bool isBrowsable = descriptor.IsBrowsable;

            // Assert
            Assert.AreEqual(isPropertyVisible, isBrowsable);
        }
Ejemplo n.º 15
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var                    svc       = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            PropertyBag            bag       = (PropertyBag)context.Instance;
            string                 pName     = context.PropertyDescriptor.Name;
            object                 rowObject = bag.SourceObject;
            PropertySpecDescriptor pd        = context.PropertyDescriptor as PropertySpecDescriptor;
            string                 name      = pd.PropTag as string;
            //string name = ModelHelper.GetPropertyNameForDescription(bag.SourceObjectType, pName);
            //if (name == null) name = pName;
            bool   complated = false;
            object res       = AppManager.Instance.ProcessEditCustomPropertyValue(rowObject, name, out complated, null);

            bag.OnValueModified(null);
            return(res);
        }
Ejemplo n.º 16
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var                    svc       = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            PropertyBag            bag       = (PropertyBag)context.Instance;
            string                 pName     = context.PropertyDescriptor.Name;
            PropertySpecDescriptor pd        = context.PropertyDescriptor as PropertySpecDescriptor;
            JSetting               setting   = pd.PropTag as JSetting;
            bool                   complated = false;
            object                 res       = AppManager.Instance.EditCustomSettingValue(setting, out complated, null);

            if (complated)
            {
                setting.ForceValueChangedEvent(this);
                bag.OnValueModified(null);
            }
            return(res);
        }
Ejemplo n.º 17
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            PropertyDescriptor[] newProps = new PropertyDescriptor[Count];

            for (int i = 0; i < Count; i++)
            {
                ArrayList attrs = new ArrayList(attributes);
                attrs.Add(new DescriptionAttribute(this[i].Description));

                if (this[i].Attributes != null)
                {
                    attrs.AddRange(this[i].Attributes);
                }

                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));
                newProps[i] = new PropertySpecDescriptor(this[i], attrArray);
            }
            return(new PropertyDescriptorCollection(newProps));
        }
Ejemplo n.º 18
0
 private void setAttrs(List<PropertyDescriptor> props, PropertySpec property)
 {
     ArrayList list = new ArrayList();
     if (property.Category != null)
     {
         list.Add(new CategoryAttribute(property.Category));
     }
     if (property.Description != null)
     {
         list.Add(new DescriptionAttribute(property.Description));
     }
     if (property.EditorTypeName != null)
     {
         list.Add(new EditorAttribute(property.EditorTypeName, typeof(UITypeEditor)));
     }
     if (property.ConverterTypeName != null)
     {
         list.Add(new TypeConverterAttribute(property.ConverterTypeName));
     }
     if (property.Attributes != null)
     {
         list.AddRange(property.Attributes);
     }
     Attribute[] attrs = (Attribute[]) list.ToArray(typeof(Attribute));
     PropertySpecDescriptor item = new PropertySpecDescriptor(property, this, property.Name, attrs);
     props.Add(item);
 }
Ejemplo n.º 19
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            // Rather than passing this function on to the default TypeDescriptor,
            // which would return the actual properties of PropertyBag, I construct
            // a list here that contains property descriptors for the elements of the
            // Properties list in the bag.

            ArrayList props = new ArrayList();

            foreach (PropertySpec property in properties)
            {
                ArrayList attrs = new ArrayList();

                // If a category, description, editor, or type converter are specified
                // in the PropertySpec, create attributes to define that relationship.
                if (property.Category != null)
                    attrs.Add(new CategoryAttribute(property.Category));

                if (property.Description != null)
                    attrs.Add(new DescriptionAttribute(property.Description));

                if (property.EditorTypeName != null)
                    attrs.Add(new EditorAttribute(property.EditorTypeName, typeof(UITypeEditor)));

                if (property.ConverterTypeName != null)
                    attrs.Add(new TypeConverterAttribute(property.ConverterTypeName));

                // Additionally, append the custom attributes associated with the
                // PropertySpec, if any.
                if (property.Attributes != null)
                    attrs.AddRange(property.Attributes);

                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create a new property descriptor for the property item, and add
                // it to the list.
                PropertySpecDescriptor pd = new PropertySpecDescriptor(property,
                                                                       this, property.Name, attrArray);
                props.Add(pd);
            }

            // Convert the list of PropertyDescriptors to a collection that the
            // ICustomTypeDescriptor can use, and return it.
            PropertyDescriptor[] propArray = (PropertyDescriptor[])props.ToArray(
                                                                       typeof(PropertyDescriptor));
            return new PropertyDescriptorCollection(propArray);
        }
Ejemplo n.º 20
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            // Rather than passing this function on to the default TypeDescriptor,
            // which would return the actual properties of PropertyBag, I construct
            // a list here that contains property descriptors for the elements of the
            // Properties list in the bag.

            var props = new ArrayList();

            foreach (PropertySpec property in _properties)
            {
                var attrs = new ArrayList();

                // If a category, description, editor, or type converter are specified
                // in the PropertySpec, create attributes to define that relationship.
                if (property.Category != null)
                {
                    if (property.Category == "08. Insert & Update Options")
                    {
                        var cslaObject = (CslaObjectInfo)GeneratorController.Current.GetSelectedItem();
                        if (cslaObject.IsEditableChild())
                        {
                            property.Category = "08. Insert, Update, Delete Options";
                        }
                    }

                    attrs.Add(new CategoryAttribute(property.Category));
                }

                if (property.Description != null)
                    attrs.Add(new DescriptionAttribute(property.Description));

                if (property.EditorTypeName != null)
                    attrs.Add(new EditorAttribute(property.EditorTypeName, typeof(UITypeEditor)));

                if (property.ConverterTypeName != null)
                    attrs.Add(new TypeConverterAttribute(property.ConverterTypeName));

                // Additionally, append the custom attributes associated with the
                // PropertySpec, if any.
                if (property.Attributes != null)
                    attrs.AddRange(property.Attributes);

                if (property.DefaultValue != null)
                    attrs.Add(new DefaultValueAttribute(property.DefaultValue));

                attrs.Add(new BrowsableAttribute(property.Browsable));
                attrs.Add(new ReadOnlyAttribute(property.ReadOnly));
                attrs.Add(new BindableAttribute(property.Bindable));

                Attribute[] attrArray = (Attribute[])attrs.ToArray(typeof(Attribute));

                // Create a new property descriptor for the property item, and add
                // it to the list.
                PropertySpecDescriptor pd = new PropertySpecDescriptor(property,
                    this, property.Name, attrArray);
                props.Add(pd);
            }

            // Convert the list of PropertyDescriptors to a collection that the
            // ICustomTypeDescriptor can use, and return it.
            PropertyDescriptor[] propArray = (PropertyDescriptor[])props.ToArray(
            typeof(PropertyDescriptor));
            return new PropertyDescriptorCollection(propArray);
        }