public CollectionForm(Type elementType) { ElementType = elementType; InitializeComponent(); ApplySetting(); toolStripSortButton.DropDownItems.AddRange(Reflector.GetAllPublicProperties(ElementType).Select(prop => { var button = new ToolStripButton() { Text = prop.Name }; button.Click += SortSelected; return(button); }).ToArray());; }
public IEnumerable <PropertyInfo> GetNestedSerializableProperties(Type type) => Reflector.GetAllPublicProperties(type) .Where(prop => IsNestedSerializableType(prop.PropertyType));
void Fill() { Type objType = Reflector.GetPropertyTypeByPath(Source.GetType(), PropertyPath); if (typeof(IList).IsAssignableFrom(objType) && objType != typeof(string)) { object source = Reflector.GetPropertyValueByPath(Source, PropertyPath); Type genericType = objType.IsArray ? objType.GetElementType() : objType.GetGenericArguments().First(); table.ColumnStyles[1].Width = 0; Type genericBindingList = (typeof(BindingList <>).MakeGenericType(genericType)); object bindingList = Activator.CreateInstance(genericBindingList, source); var dataEntryGridView = new DataEntryGridView() { BorderStyle = BorderStyle.None, BackgroundColor = SystemColors.Control, AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill, Dock = DockStyle.Fill }; if (genericType.IsPrimitive) { Type genericListDataSource = (typeof(BindingListSourceAdapter <>).MakeGenericType(genericType)); object listDataSource = Activator.CreateInstance(genericListDataSource, bindingList); dataEntryGridView.DataSource = listDataSource; } else { dataEntryGridView.DataSource = bindingList; } table.Controls.Add(dataEntryGridView); return; } foreach (var prop in Reflector.GetAllPublicProperties(objType)) { var propertyType = prop.PropertyType; var propName = prop.Name; var currentPropPath = string.IsNullOrEmpty(PropertyPath) ? propName : $"{PropertyPath}.{propName}"; Add(propName); Control control; if (propertyType.IsPrimitive) { if (propertyType == typeof(bool)) { control = new CheckBox(); control.DataBindings.Add(new(nameof(CheckBox.Checked), Source, currentPropPath)); } else { control = new ValidatingTextBox(propertyType); control.DataBindings.Add(new(nameof(ValidatingTextBox.Value), Source, currentPropPath)); } } else if (propertyType.IsEnum) { control = new ValidatingEnumComboBox(propertyType); control.DataBindings.Add(new(nameof(ValidatingEnumComboBox.Value), Source, currentPropPath)); } else if (propertyType == typeof(DateTime)) { control = new DateTimePicker(); control.DataBindings.Add(new(nameof(DateTimePicker.Value), Source, currentPropPath)); } else if (propertyType == typeof(string)) { control = new TextBox(); control.DataBindings.Add(new Binding(nameof(TextBox.Text), Source, currentPropPath)); } else { control = new Button() { Text = "...", Size = new(40, 20) }; control.Click += (_, _) => new DataEntryForm(Source, currentPropPath).Show(); } Add(control); } }