Exemplo n.º 1
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object obj, Attribute[] attributes)
        {
            PropertyDescriptorCollection propertyDescriptorCollection = new PropertyDescriptorCollection(null);
            CustomAttributes             customAttributes             = obj as CustomAttributes;

            if (customAttributes != null && context != null)
            {
                Series series = (customAttributes.DataPointAttributes is Series) ? ((Series)customAttributes.DataPointAttributes) : customAttributes.DataPointAttributes.series;
                if (series != null && series.chart != null && series.chart.chartPicture != null && series.chart.chartPicture.common != null)
                {
                    foreach (CustomAttributeInfo registeredCustomAttribute in ((CustomAttributeRegistry)series.chart.chartPicture.common.container.GetService(typeof(CustomAttributeRegistry))).registeredCustomAttributes)
                    {
                        if (IsApplicableCustomAttribute(registeredCustomAttribute, context.Instance))
                        {
                            Attribute[] propertyAttributes           = GetPropertyAttributes(registeredCustomAttribute);
                            CustomAttributesPropertyDescriptor value = new CustomAttributesPropertyDescriptor(typeof(CustomAttributes), registeredCustomAttribute.Name, registeredCustomAttribute.ValueType, propertyAttributes, registeredCustomAttribute);
                            propertyDescriptorCollection.Add(value);
                        }
                    }
                    Attribute[] attributes2 = new Attribute[3]
                    {
                        new NotifyParentPropertyAttribute(notifyParent: true),
                        new RefreshPropertiesAttribute(RefreshProperties.All),
                        new DescriptionAttribute(SR.DescriptionAttributeUserDefined)
                    };
                    CustomAttributesPropertyDescriptor value2 = new CustomAttributesPropertyDescriptor(typeof(CustomAttributes), "UserDefined", typeof(string), attributes2, null);
                    propertyDescriptorCollection.Add(value2);
                }
            }
            return(propertyDescriptorCollection);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a collection of properties for the type of array specified by the value parameter,
        /// using the specified context and properties.
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that provides a format context.</param>
        /// <param name="obj">An Object that specifies the type of array for which to get properties.</param>
        /// <param name="attributes">An array of type Attribute that is used as a filter.</param>
        /// <returns>A PropertyDescriptorCollection with the properties that are exposed for this data type, or a null reference (Nothing in Visual Basic) if there are no properties.</returns>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object obj, Attribute[] attributes)
        {
            PropertyDescriptorCollection propCollection = new PropertyDescriptorCollection(null);
            CustomProperties             attr           = obj as CustomProperties;

            if (attr != null && context != null)
            {
                // Get series associated with custom attribute
                Series series = (attr.DataPointCustomProperties is Series) ? ((Series)attr.DataPointCustomProperties) : attr.DataPointCustomProperties.series;
                if (series != null &&
                    series.Common != null)
                {
                    // Loop through all registered custom properties
                    CustomPropertyRegistry registry = (CustomPropertyRegistry)series.Common.container.GetService(typeof(CustomPropertyRegistry));
                    foreach (CustomPropertyInfo attrInfo in registry.registeredCustomProperties)
                    {
                        // Check if attribute description matches curent selection in property browser
                        if (IsApplicableCustomProperty(attrInfo, context.Instance))
                        {
                            // Get array of property properties
                            Attribute[] propAttributes = GetPropertyAttributes(attrInfo);

                            // Create property descriptor
                            CustomAttributesPropertyDescriptor propertyDescriptor = new CustomAttributesPropertyDescriptor(
                                typeof(CustomProperties),
                                attrInfo.Name,
                                attrInfo.ValueType,
                                propAttributes,
                                attrInfo);

                            // Add descriptor into the collection
                            propCollection.Add(propertyDescriptor);
                        }
                    }

                    // Always add "UserDefined" property for all user defined custom properties
                    Attribute[] propUserDefinedAttributes = new Attribute[] {
                        new NotifyParentPropertyAttribute(true),
                        new RefreshPropertiesAttribute(RefreshProperties.All),
                        new DescriptionAttribute(SR.DescriptionAttributeUserDefined)
                    };

                    // Create property descriptor
                    CustomAttributesPropertyDescriptor propertyUserDefinedDescriptor = new CustomAttributesPropertyDescriptor(
                        typeof(CustomProperties),
                        "UserDefined",
                        typeof(string),
                        propUserDefinedAttributes,
                        null);

                    // Add descriptor into the collection
                    propCollection.Add(propertyUserDefinedDescriptor);
                }
            }

            return(propCollection);
        }