Пример #1
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

                        // DevDiv2 518025   
                        // 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;
        }
Пример #2
0
 public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
 {
     return(TypeDescriptor.GetProperties(typeof(TableLayoutPanelCellPosition), attributes).Sort(new string[] { "Column", "Row" }));
 }
Пример #3
0
 private static PropertyDescriptorCollection GetListItemPropertiesByType(Type type) {
     return TypeDescriptor.GetProperties(GetListItemType(type), BrowsableAttributeList);
 }
Пример #4
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) }));
        }
Пример #5
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 == 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 != null && list.Count > 0)
                    {
                        itemProps = TypeDescriptor.GetProperties(list[0]);
                    }
                }

                if (itemProps != 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);
        }
        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] = ImageList.Indexer.DefaultIndex;
                    }
                    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[] { ImageList.Indexer.DefaultIndex }));
            }
            else
            {
                return(new StandardValuesCollection(Array.Empty <object>()));
            }
        }
 private PropertyDescriptorCollection GetBrowsableProperties(Type t)
 {
     Attribute [] att = new System.Attribute [1];
     att [0] = new BrowsableAttribute(true);
     return(TypeDescriptor.GetProperties(t, att));
 }
Пример #8
0
        /// <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;
                        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(new object[0]));
            }
        }