//public PropertyCollection(object instance) // : this(instance, false) //{ } public PropertyCollection(object instance, bool noCategory, bool automaticlyExpandObjects, string filter) { var groups = new Dictionary <string, PropertyCategory>(); var useCustomTypeConverter = false; PropertyDescriptorCollection properties; if (instance != null) { var 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[] { }); } var propertyCollection = new List <Property>(); foreach (PropertyDescriptor propertyDescriptor in properties) { if (useCustomTypeConverter) { var 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 (var property in propertyCollection) { if (filter == "" || property.Name.ToLower().Contains(filter)) { Items.Add(property); } } } else { foreach (var 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) { var groups = new Dictionary<string, PropertyCategory>(); var useCustomTypeConverter = false; PropertyDescriptorCollection properties; if(instance != null) { var 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[] { }); } var propertyCollection = new List<Property>(); foreach(PropertyDescriptor propertyDescriptor in properties) { if(useCustomTypeConverter) { var 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(var property in propertyCollection) { if(filter == "" || property.Name.ToLower().Contains(filter)) { Items.Add(property); } } } else { foreach(var 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); } } } }