public override PropertyDescriptorCollection GetProperties()
        {
            if (_properties == null) {
                // Get properties from our parent
                var originalCollection = base.GetProperties();

                // Set _properties to avoid a stack overflow when CreateProjectionProperties
                // ends up recursively calling TypeDescriptor.GetProperties on a type.
                _properties = originalCollection;

                var customDescriptorsCreated = false;
                var tempPropertyDescriptors = new List<PropertyDescriptor>();

                // for every property exposed by our parent, see if we have additional metadata to add,
                // and if we do we need to add a wrapper PropertyDescriptor to add the new attributes
                foreach (var propDescriptor in _properties.OfType<PropertyDescriptor>()) {
                    var newMetadata = GetAdditionalAttributes(propDescriptor);
                    if (newMetadata.Length > 0) {
                        tempPropertyDescriptors.Add(new DataControllerPropertyDescriptor(propDescriptor, newMetadata));
                        customDescriptorsCreated = true;
                    }
                    else
                        tempPropertyDescriptors.Add(propDescriptor);
                }

                if (customDescriptorsCreated)
                    _properties = new PropertyDescriptorCollection(tempPropertyDescriptors.ToArray(), true);
            }

            return _properties;
        }
Пример #2
0
        private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection originalCollection)
        {
            // Create an enumerator containing only the properties that are not in the provided list of property names
            // and fill an array with those selected properties

            IEnumerable<PropertyDescriptor> selectedProperties = originalCollection.OfType<PropertyDescriptor>().Where(p => !_excludeBrowsableProperties.Contains(p.Name));
            PropertyDescriptor[] descriptors = selectedProperties.ToArray();

            // Return a PropertyDescriptorCollection containing only the filtered descriptors
            PropertyDescriptorCollection newCollection = new PropertyDescriptorCollection(descriptors);
            return newCollection;
        }
 private void InitializeColumns(PropertyDescriptorCollection columnDescriptors) {
     _columns = columnDescriptors.OfType<PropertyDescriptor>().Select(p => new SimpleColumnProvider(this, p)).OfType<ColumnProvider>().ToList();
 }