private Dictionary<string, CustomPropertyInfo> GetItemProperties() { var propertiesByName = new Dictionary<string, CustomPropertyInfo>(); if (CollectionView != null) { ItemType = GetItemType(CollectionView); object currentItem = CollectionView.CurrentItem; if (currentItem == null) { IEnumerator enumerator = CollectionView.SourceCollection.GetEnumerator(); try { if (enumerator.MoveNext()) { currentItem = enumerator.Current; } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } ICustomTypeDescriptor customTypeDescriptor = currentItem as ICustomTypeDescriptor; if (customTypeDescriptor != null) { foreach (PropertyDescriptor property in customTypeDescriptor.GetProperties()) { string name = ObjectEx.EscapeName(property.Name); propertiesByName[name] = new CustomPropertyInfo(name, property.Name, property.PropertyType, property.IsReadOnly); } return propertiesByName; } ITypedList typedList = CollectionView.SourceCollection as ITypedList; if (typedList != null) { foreach (PropertyDescriptor property in typedList.GetItemProperties(null)) { string name = ObjectEx.EscapeName(property.Name); propertiesByName[property.Name] = new CustomPropertyInfo(name, property.Name, property.PropertyType, property.IsReadOnly); } return propertiesByName; } if (ItemType != null && !Util.Util.IsPrimitive(ItemType)) { PropertyInfo[] properties = ItemType.GetProperties(); for (int i = 0; i < properties.Length; i++) { PropertyInfo property = properties[i]; ParameterInfo[] indexParameters = property.GetIndexParameters(); if (indexParameters == null || indexParameters.Length <= 0) { propertiesByName[property.Name] = new CustomPropertyInfo(property); } } } } return propertiesByName; }
private void BindAutoColumn(Column c, CustomPropertyInfo cpi) { Binding binding = new Binding(); binding.Path = new PropertyPath(cpi.Name); binding.Mode = (cpi.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay); binding.Converter = _defaultColumnValueConverter; binding.ConverterParameter = c; Util.Util.SetBindingValidation(binding, ShowErrors); c.ColumnName = cpi.DisplayName; c.Binding = binding; c.PropertyInfo = cpi.PropertyInfo; c.IsReadOnly = cpi.IsReadOnly; InitializeAutoColumn(c, cpi.PropertyType); }