protected override IEnumerable <PropertyItem> GenerateSubPropertiesCore()
        {
            var propertyItems = new List <PropertyItem>();

            if (SelectedObject != null)
            {
                try
                {
                    List <PropertyDescriptor> descriptors = ObjectContainerHelperBase.GetPropertyDescriptors(SelectedObject, this.PropertyContainer.HideInheritedProperties);
                    foreach (var descriptor in descriptors)
                    {
                        var  propertyDef = this.GetPropertyDefinition(descriptor);
                        bool isBrowsable = false;

                        var isPropertyBrowsable = this.PropertyContainer.IsPropertyVisible(descriptor);
                        if (isPropertyBrowsable.HasValue)
                        {
                            isBrowsable = isPropertyBrowsable.Value;
                        }
                        else
                        {
#if !VS2008
                            var displayAttribute = PropertyGridUtilities.GetAttribute <DisplayAttribute>(descriptor);
                            if (displayAttribute != null)
                            {
                                var autoGenerateField = displayAttribute.GetAutoGenerateField();
                                isBrowsable = this.PropertyContainer.AutoGenerateProperties &&
                                              ((autoGenerateField.HasValue && autoGenerateField.Value) || !autoGenerateField.HasValue);
                            }
                            else
#endif
                            {
                                isBrowsable = descriptor.IsBrowsable && this.PropertyContainer.AutoGenerateProperties;
                            }

                            if (propertyDef != null)
                            {
                                isBrowsable = propertyDef.IsBrowsable.GetValueOrDefault(isBrowsable);
                            }
                        }

                        if (isBrowsable)
                        {
                            var prop = this.CreatePropertyItem(descriptor, propertyDef);
                            if (prop != null)
                            {
                                propertyItems.Add(prop);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    //TODO: handle this some how
                    Debug.WriteLine("Property creation failed.");
                    Debug.WriteLine(e.StackTrace);
                }
            }

            return(propertyItems);
        }
        protected override string GetDefaultPropertyName()
        {
            object selectedObject = SelectedObject;

            return((selectedObject != null) ? ObjectContainerHelperBase.GetDefaultPropertyName(SelectedObject) : ( string )null);
        }
        protected override IEnumerable <PropertyItem> GenerateSubPropertiesCore()
        {
            var propertyItems = new List <PropertyItem>();

            if (SelectedObject != null)
            {
                try
                {
                    List <PropertyDescriptor> descriptors = ObjectContainerHelperBase.GetPropertyDescriptors(SelectedObject);
                    if (!PropertyContainer.AutoGenerateProperties)
                    {
                        List <PropertyDescriptor> specificProperties = new List <PropertyDescriptor>();
                        if (PropertyContainer.PropertyDefinitions != null)
                        {
                            foreach (PropertyDefinition pd in PropertyContainer.PropertyDefinitions)
                            {
                                foreach (object targetProperty in pd.TargetProperties)
                                {
                                    PropertyDescriptor descriptor = null;
                                    // If the target is a string, compare it with the property name.
                                    var propName = targetProperty as string;
                                    if (propName != null)
                                    {
                                        descriptor = descriptors.FirstOrDefault(d => d.Name == propName);
                                    }

                                    // If the target is a Type, compare it with the property type.
                                    var propType = targetProperty as Type;
                                    if (propType != null)
                                    {
                                        descriptor = descriptors.FirstOrDefault(d => d.PropertyType == propType);
                                    }

                                    if (descriptor != null)
                                    {
                                        specificProperties.Add(descriptor);
                                        descriptors.Remove(descriptor);
                                    }
                                }
                            }
                        }

                        descriptors = specificProperties;
                    }

                    foreach (PropertyDescriptor descriptor in descriptors)
                    {
                        if (descriptor.IsBrowsable)
                        {
                            propertyItems.Add(CreatePropertyItem(descriptor));
                        }
                    }
                }
                catch (Exception)
                {
                    //TODO: handle this some how
                }
            }

            return(propertyItems);
        }