public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { var sourceProperties = base.GetProperties(attributes); if ((sourceProperties == null) || (sourceProperties.Count == 0)) { return(sourceProperties); } var entry = this.GetEntry(); var replaceProperties = default(Dictionary <PropertyDescriptor, DataItemPropertyDescriptorBase>); lock ( entry ) { replaceProperties = entry.Properties; if (replaceProperties == null) { replaceProperties = new Dictionary <PropertyDescriptor, DataItemPropertyDescriptorBase>(); entry.Properties = replaceProperties; var factory = new DataItemPropertyDescriptorFactory(this); foreach (var sourceProperty in sourceProperties.Cast <PropertyDescriptor>()) { var descriptor = factory.CreatePropertyDescriptor(sourceProperty); if (descriptor != null) { replaceProperties.Add(sourceProperty, descriptor); } } } if (replaceProperties.Count == 0) { return(sourceProperties); } } var destinationProperties = new PropertyDescriptor[sourceProperties.Count]; for (int i = 0; i < sourceProperties.Count; i++) { var sourceProperty = sourceProperties[i]; DataItemPropertyDescriptorBase destinationProperty; if (replaceProperties.TryGetValue(sourceProperty, out destinationProperty)) { destinationProperties[i] = destinationProperty; } else { destinationProperties[i] = sourceProperty; } } return(new PropertyDescriptorCollection(destinationProperties)); }
internal DataItemPropertyDescriptorBase CreatePropertyDescriptor(PropertyDescriptor source) { if (!DataItemPropertyDescriptorFactory.IsReflected(source)) { return(null); } var componentType = source.ComponentType; PropertyInfo propertyInfo; try { propertyInfo = componentType.GetProperty(source.Name, BindingFlags.Public | BindingFlags.Instance); if ((propertyInfo == null) || DataItemPropertyDescriptorFactory.IsIndexed(propertyInfo)) { return(null); } } catch (AmbiguousMatchException) { return(null); } var propertyType = propertyInfo.PropertyType; Debug.Assert(propertyType == source.PropertyType); var creatorHelper = DelegateCreatorHelperFactory.CreateHelper(componentType, propertyType); var getter = DataItemPropertyDescriptorFactory.CreateGetter(propertyInfo, creatorHelper); if (getter == null) { return(null); } var setter = DataItemPropertyDescriptorFactory.CreateSetter(propertyInfo, creatorHelper); var resetter = DataItemPropertyDescriptorFactory.CreateResetter(componentType, propertyInfo, creatorHelper); var propertyChangedEvent = this.GetPropertyChangedEvent(propertyInfo.Name); if (propertyChangedEvent != null) { return(new ValueChangeDataItemPropertyDescriptor(m_typeDescriptor, source, componentType, propertyType, getter, setter, resetter, propertyChangedEvent)); } return(new DataItemPropertyDescriptor(m_typeDescriptor, source, componentType, propertyType, getter, setter, resetter)); }
internal DataItemIndexerDescriptor GetIndexer(object[] indexValues) { if ((indexValues == null) || (indexValues.Length <= 0) || (m_targetType == null)) { return(null); } var entry = this.GetEntry(); lock ( entry ) { var indexers = entry.Indexers; var descriptor = default(DataItemIndexerDescriptor); var key = new IndexerKey(indexValues); if ((indexers != null) && (indexers.TryGetValue(key, out descriptor))) { return(descriptor); } var indexer = this.CreateIndexerDescriptor(indexValues); if (indexer == null) { return(null); } var factory = new DataItemPropertyDescriptorFactory(this); descriptor = factory.CreateIndexerDescriptor(indexer); if (descriptor == null) { return(null); } if (indexers == null) { indexers = new Dictionary <IndexerKey, DataItemIndexerDescriptor>(); entry.Indexers = indexers; } indexers.Add(key, descriptor); return(descriptor); } }