//public PropertyCollection(object instance) // : this(instance, false) //{ } public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter) { Dictionary<string, PropertyCategory> groups = new Dictionary<string, PropertyCategory>(); bool useCustomTypeConverter = false; PropertyDescriptorCollection properties; if (instance != null) { TypeConverter tc = TypeDescriptor.GetConverter(instance); if (tc == null || !tc.GetPropertiesSupported()) { if (instance is ICustomTypeDescriptor) properties = ((ICustomTypeDescriptor)instance).GetProperties(); else properties = TypeDescriptor.GetProperties(instance.GetType()); //I changed here from instance to instance.GetType, so that only the Direct Properties are shown! } else { properties = tc.GetProperties(instance); useCustomTypeConverter = true; } } else properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { }); List<Property> propertyCollection = new List<Property>(); foreach (PropertyDescriptor propertyDescriptor in properties) { if (useCustomTypeConverter) { Property property = new Property(instance, propertyDescriptor); propertyCollection.Add(property); } else { CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter); if (noCategory) propertyCollection.Sort(Property.CompareByName); else propertyCollection.Sort(Property.CompareByCategoryThenByName); } } if (noCategory) { foreach (Property property in propertyCollection) { if (filter == "" || property.Name.ToLower().Contains(filter)) Items.Add(property); } } else { foreach (Property property in propertyCollection) { if (filter == "" || property.Name.ToLower().Contains(filter)) { PropertyCategory propertyCategory; var category = property.Category ?? string.Empty; // null category handled here if (groups.ContainsKey(category)) { propertyCategory = groups[category]; } else { propertyCategory = new PropertyCategory(property.Category); groups[category] = propertyCategory; Items.Add(propertyCategory); } propertyCategory.Items.Add(property); } } } }
//public PropertyCollection(object instance) // : this(instance, false) //{ } public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter) { Dictionary <string, PropertyCategory> groups = new Dictionary <string, PropertyCategory>(); bool useCustomTypeConverter = false; PropertyDescriptorCollection properties; if (instance != null) { TypeConverter tc = TypeDescriptor.GetConverter(instance); if (tc == null || !tc.GetPropertiesSupported()) { if (instance is ICustomTypeDescriptor) { properties = ((ICustomTypeDescriptor)instance).GetProperties(); } else { properties = TypeDescriptor.GetProperties(instance.GetType()); //I changed here from instance to instance.GetType, so that only the Direct Properties are shown! } } else { properties = tc.GetProperties(instance); useCustomTypeConverter = true; } } else { properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { }); } List <Property> propertyCollection = new List <Property>(); foreach (PropertyDescriptor propertyDescriptor in properties) { if (useCustomTypeConverter) { Property property = new Property(instance, propertyDescriptor); propertyCollection.Add(property); } else { CollectProperties(instance, propertyDescriptor, propertyCollection, automaticlyExpandObjects, filter); if (noCategory) { propertyCollection.Sort(Property.CompareByName); } else { propertyCollection.Sort(Property.CompareByCategoryThenByName); } } } if (noCategory) { foreach (Property property in propertyCollection) { if (filter == "" || property.Name.ToLower().Contains(filter)) { Items.Add(property); } } } else { foreach (Property property in propertyCollection) { if (filter == "" || property.Name.ToLower().Contains(filter)) { PropertyCategory propertyCategory; var category = property.Category ?? string.Empty; // null category handled here if (groups.ContainsKey(category)) { propertyCategory = groups[category]; } else { propertyCategory = new PropertyCategory(property.Category); groups[category] = propertyCategory; Items.Add(propertyCategory); } propertyCategory.Items.Add(property); } } } }