Example #1
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Padding), attributes);

            return(props.Sort(new string[] { nameof(Padding.All), nameof(Padding.Left), nameof(Padding.Top), nameof(Padding.Right), nameof(Padding.Bottom) }));
        }
        /// <include file='doc\ImageIndexConverter.uex' path='docs/doc[@for="ImageIndexConverter.GetStandardValues"]/*' />
        /// <devdoc>
        ///      Retrieves a collection containing a set of standard values
        ///      for the data type this validator is designed for.  This
        ///      will return null if the data type does not support a
        ///      standard set of values.
        /// </devdoc>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                object instance = context.Instance;

                PropertyDescriptor imageListProp = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance);

                while (instance != null && imageListProp == null)
                {
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(instance);

                    foreach (PropertyDescriptor prop in props)
                    {
                        if (typeof(ImageList).IsAssignableFrom(prop.PropertyType))
                        {
                            imageListProp = prop;
                            break;
                        }
                    }

                    if (imageListProp == null)
                    {
                        // We didn't find the image list in this component.  See if the
                        // component has a "parent" property.  If so, walk the tree...
                        //
                        PropertyDescriptor parentProp = props[ParentImageListProperty];
                        if (parentProp != null)
                        {
                            instance = parentProp.GetValue(instance);
                        }
                        else
                        {
                            // Stick a fork in us, we're done.
                            //
                            instance = null;
                        }
                    }
                }

                if (imageListProp != null)
                {
                    ImageList imageList = (ImageList)imageListProp.GetValue(instance);

                    if (imageList != null)
                    {
                        // Create array to contain standard values
                        //
                        object[] values;
                        int      nImages = imageList.Images.Count + 2;
                        values = new object[nImages];
                        values[nImages - 2] = -1;
                        values[nImages - 1] = -2;

                        // Fill in the array
                        //
                        for (int i = 0; i < nImages - 2; i++)
                        {
                            values[i] = i;
                        }
                        return(new StandardValuesCollection(values));
                    }
                }
            }

            return(new StandardValuesCollection(new object[] { -1, -2 }));
        }
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext?context, object value, Attribute[]?attributes)
        {
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(SelectionRange), attributes);

            return(props.Sort(new string[] { "Start", "End" }));
        }
Example #4
0
        protected virtual PropertyDescriptorCollection GetItemProperties(Type listType, int offset, ArrayList dataSources, ArrayList listAccessors)
        {
            if (listAccessors.Count < offset)
            {
                return(null);
            }

            if (listAccessors.Count == offset)
            {
                if (!typeof(IList).IsAssignableFrom(listType))
                {
                    return(TypeDescriptor.GetProperties(listType));
                }

                foreach (PropertyInfo property in listType.GetProperties())
                {
                    if (property.Name == "Item" && property.PropertyType != typeof(object))
                    {
                        return(TypeDescriptor.GetProperties(property.PropertyType, new Attribute[] { new BrowsableAttribute(true) }));
                    }
                }

                // return the properties on the type of the first element in the list
                if (dataSources[offset - 1] is IList list && list.Count > 0)
                {
                    return(TypeDescriptor.GetProperties(list[0]));
                }

                return(null);
            }

            if (typeof(IList).IsAssignableFrom(listType))
            {
                PropertyDescriptorCollection itemProps = null;
                foreach (PropertyInfo property in listType.GetProperties())
                {
                    if (property.Name == "Item" && property.PropertyType != typeof(object))
                    {
                        // get all the properties that are not marked as Browsable(false)
                        itemProps = TypeDescriptor.GetProperties(property.PropertyType, new Attribute[] { new BrowsableAttribute(true) });
                    }
                }

                if (itemProps is null)
                {
                    // Use the properties on the type of the first element in the list
                    // if offset == 0, then this means that the first dataSource did not have a strongly typed Item property.
                    // the dataSources are added only for relatedCurrencyManagers, so in this particular case
                    // we need to use the dataSource in the currencyManager.
                    IList list;
                    if (offset == 0)
                    {
                        list = DataSource as IList;
                    }
                    else
                    {
                        list = dataSources[offset - 1] as IList;
                    }

                    if (list is not null && list.Count > 0)
                    {
                        itemProps = TypeDescriptor.GetProperties(list[0]);
                    }
                }

                if (itemProps is not null)
                {
                    for (int j = 0; j < itemProps.Count; j++)
                    {
                        if (itemProps[j].Equals(listAccessors[offset]))
                        {
                            return(GetItemProperties(itemProps[j].PropertyType, offset + 1, dataSources, listAccessors));
                        }
                    }
                }
            }
            else
            {
                foreach (PropertyInfo property in listType.GetProperties())
                {
                    if (property.Name.Equals(((PropertyDescriptor)listAccessors[offset]).Name))
                    {
                        return(GetItemProperties(property.PropertyType, offset + 1, dataSources, listAccessors));
                    }
                }
            }

            return(null);
        }
Example #5
0
        /// <summary>
        ///      Retrieves a collection containing a set of standard values
        ///      for the data type this validator is designed for.  This
        ///      will return null if the data type does not support a
        ///      standard set of values.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                object instance = context.Instance;

                ImageList imageList = null;

                PropertyDescriptorCollection listViewItemProps = TypeDescriptor.GetProperties(instance);
                PropertyDescriptor           listViewProp      = listViewItemProps["ListView"];

                if (listViewProp != null)
                {
                    // Grab the ListView property off of the TreeNode.
                    object listViewInstance = listViewProp.GetValue(instance);

                    if (listViewInstance != null)
                    {
                        // Get the ImageList property from the ListView and set it to be the currentImageList.
                        PropertyDescriptorCollection listViewProps             = TypeDescriptor.GetProperties(listViewInstance);
                        PropertyDescriptor           listViewImageListProperty = listViewProps["StateImageList"];
                        if (listViewImageListProperty != null)
                        {
                            imageList = (ImageList)listViewImageListProperty.GetValue(listViewInstance);
                        }
                    }
                }

                if (imageList != null)
                {
                    // Create array to contain standard values
                    //
                    object[] values;
                    int      nImages = imageList.Images.Count;
                    if (IncludeNoneAsStandardValue)
                    {
                        values          = new object[nImages + 1];
                        values[nImages] = -1;
                    }
                    else
                    {
                        values = new object[nImages];
                    }


                    // Fill in the array
                    //
                    for (int i = 0; i < nImages; i++)
                    {
                        values[i] = i;
                    }

                    return(new StandardValuesCollection(values));
                }
            }
            if (IncludeNoneAsStandardValue)
            {
                return(new StandardValuesCollection(new object[] { -1 }));
            }
            else
            {
                return(new StandardValuesCollection(Array.Empty <object>()));
            }
        }
Example #6
0
        private static PropertyDescriptorCollection GetListItemPropertiesByEnumerable(IEnumerable enumerable)
        {
            PropertyDescriptorCollection pdc = null;
            Type targetType = enumerable.GetType();

            if (typeof(Array).IsAssignableFrom(targetType))
            {
                pdc = TypeDescriptor.GetProperties(targetType.GetElementType(), BrowsableAttributeList);
            }
            else
            {
                ITypedList typedListEnumerable = enumerable as ITypedList;
                if (typedListEnumerable != null)
                {
                    pdc = typedListEnumerable.GetItemProperties(null);
                }
                else
                {
                    PropertyInfo indexer = GetTypedIndexer(targetType);

                    if (indexer != null && !typeof(ICustomTypeDescriptor).IsAssignableFrom(indexer.PropertyType))
                    {
                        Type type = indexer.PropertyType;
                        pdc = TypeDescriptor.GetProperties(type, BrowsableAttributeList);

                        // Reflection, and consequently TypeDescriptor would not return properties defined on the "base" interface,
                        // for example
                        // public interface IPerson {String FirstName { get; set; }}
                        // public interface ITeacher : IPerson {int ClassRoom { get; set; }}
                        // typeof (ITeacher).GetProperties() would return only the "ClassRoom" property

                        // if (type.IsInterface) {
                        //     Type[] interfaces = type.GetInterfaces();
                        //    // initialize the list to an arbitrary length greater than pdc.Count
                        //     List<PropertyDescriptor> merged = new List<PropertyDescriptor>(pdc.Count * 2 + 1);
                        //     foreach (Type baseInterface in interfaces) {
                        //         PropertyDescriptorCollection props = TypeDescriptor.GetProperties(baseInterface, BrowsableAttributeList);
                        //         if (props != null) {
                        //             foreach (PropertyDescriptor p in props) {
                        //                 merged.Add(p);
                        //             }
                        //         }
                        //     }
                        //     if (merged.Count != 0) {
                        //         PropertyDescriptor[] props = new PropertyDescriptor[pdc.Count];
                        //         pdc.CopyTo(props, 0);
                        //         merged.AddRange(props);
                        //         pdc = new PropertyDescriptorCollection(merged.ToArray());
                        //     }
                        // }
                    }
                }
            }

            // See if we were successful - if not, return the shape of the first
            // item in the list
            if (null == pdc)
            {
                object instance = GetFirstItemByEnumerable(enumerable);
                if (enumerable is string)
                {
                    pdc = TypeDescriptor.GetProperties(enumerable, BrowsableAttributeList);
                }
                else if (instance == null)
                {
                    pdc = new PropertyDescriptorCollection(null);
                }
                else
                {
                    pdc = TypeDescriptor.GetProperties(instance, BrowsableAttributeList);

                    if (!(enumerable is IList) && (pdc == null || pdc.Count == 0))
                    {
                        pdc = TypeDescriptor.GetProperties(enumerable, BrowsableAttributeList);
                    }
                }
            }

            // Return results
            return(pdc);
        }
Example #7
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                object             instance      = context.Instance;
                PropertyDescriptor imageListProp = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance);

                while (instance != null && imageListProp is null)
                {
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(instance);

                    foreach (PropertyDescriptor prop in props)
                    {
                        if (typeof(ImageList).IsAssignableFrom(prop.PropertyType))
                        {
                            imageListProp = prop;
                            break;
                        }
                    }

                    if (imageListProp is null)
                    {
                        // We didn't find the image list in this component.  See if the
                        // component has a "parent" property.  If so, walk the tree...
                        //
                        PropertyDescriptor parentProp = props[ParentImageListProperty];
                        if (parentProp != null)
                        {
                            instance = parentProp.GetValue(instance);
                        }
                        else
                        {
                            // Stick a fork in us, we're done.
                            //
                            instance = null;
                        }
                    }
                }

                if (imageListProp != null)
                {
                    ImageList imageList = (ImageList)imageListProp.GetValue(instance);

                    if (imageList != null)
                    {
                        // Create array to contain standard values
                        //
                        object[] values;
                        int      nImages = imageList.Images.Count;
                        if (IncludeNoneAsStandardValue)
                        {
                            values          = new object[nImages + 1];
                            values[nImages] = string.Empty;
                        }
                        else
                        {
                            values = new object[nImages];
                        }

                        // Fill in the array
                        //
                        StringCollection imageKeys = imageList.Images.Keys;
                        for (int i = 0; i < imageKeys.Count; i++)
                        {
                            if ((imageKeys[i] != null) && (imageKeys[i].Length != 0))
                            {
                                values[i] = imageKeys[i];
                            }
                        }

                        return(new StandardValuesCollection(values));
                    }
                }
            }

            if (IncludeNoneAsStandardValue)
            {
                return(new StandardValuesCollection(new object[] { "" }));
            }
            else
            {
                return(new StandardValuesCollection(Array.Empty <object>()));
            }
        }
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(TableLayoutPanelCellPosition), attributes);

            return(props.Sort(new string[] { "Column", "Row" }));
        }
Example #9
0
            /// <include file='doc\LinkArea.uex' path='docs/doc[@for="LinkArea.LinkAreaConverter.GetProperties"]/*' />
            /// <devdoc>
            ///      Retrieves the set of properties for this type.  By default, a type has
            ///      does not return any properties.  An easy implementation of this method
            ///      can just call TypeDescriptor.GetProperties for the correct data type.
            /// </devdoc>
            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
            {
                PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(LinkArea), attributes);

                return(props.Sort(new string[] { "Start", "Length" }));
            }
Example #10
0
            // IPropertyNotifySink methods

            HRESULT IPropertyNotifySink.OnChanged(DispatchID dispid)
            {
                // Some controls fire OnChanged() notifications when getting values of some properties.
                // To prevent this kind of recursion, we check to see if we are already inside a OnChanged() call.
                if (_host.NoComponentChangeEvents != 0)
                {
                    return(HRESULT.S_OK);
                }

                _host.NoComponentChangeEvents++;
                try
                {
                    AxPropertyDescriptor?prop = null;

                    Debug.WriteLineIf(s_axHTraceSwitch.TraceVerbose, "in OnChanged");

                    if (dispid != DispatchID.UNKNOWN)
                    {
                        prop = _host.GetPropertyDescriptorFromDispid(dispid);
                        if (prop is not null)
                        {
                            prop.OnValueChanged(_host);
                            if (!prop.SettingValue)
                            {
                                prop.UpdateTypeConverterAndTypeEditor(true);
                            }
                        }
                    }
                    else
                    {
                        // update them all for DISPID_UNKNOWN.
                        PropertyDescriptorCollection props = ((ICustomTypeDescriptor)_host).GetProperties();
                        foreach (PropertyDescriptor p in props)
                        {
                            prop = p as AxPropertyDescriptor;
                            if (prop is not null && !prop.SettingValue)
                            {
                                prop.UpdateTypeConverterAndTypeEditor(true);
                            }
                        }
                    }

                    if (_host.Site.TryGetService(out IComponentChangeService? changeService))
                    {
                        try
                        {
                            changeService.OnComponentChanging(_host, prop);
                        }
                        catch (CheckoutException e) when(e == CheckoutException.Canceled)
                        {
                            return(HRESULT.S_OK);
                        }

                        // Now notify the change service that the change was successful.
                        changeService.OnComponentChanged(_host, prop, oldValue: null, prop?.GetValue(_host));
                    }
                }
                catch (Exception ex)
                {
                    Debug.Fail(ex.ToString());
                    throw;
                }
                finally
                {
                    _host.NoComponentChangeEvents--;
                }

                return(HRESULT.S_OK);
            }