private PropertyDescriptorCollection GetProperties(Column column) { using (BindingSource source = new BindingSource()) { source.DataSource = column.Reference != null ? column.Reference : column.DataType; // to get properties list of ICustomTypeDescriptor type, we need an instance object instance = null; if (source.DataSource is Type && typeof(ICustomTypeDescriptor).IsAssignableFrom(source.DataSource as Type)) { try { GetTypeInstanceEventArgs args = new GetTypeInstanceEventArgs(source.DataSource as Type); Config.ReportSettings.OnGetBusinessObjectTypeInstance(null, args); instance = args.Instance; source.DataSource = instance; } catch { } } // generic list? get element type if (column.Reference == null && column.DataType.IsGenericType) { source.DataSource = column.DataType.GetGenericArguments()[0]; } PropertyDescriptorCollection properties = source.GetItemProperties(null); PropertyDescriptorCollection filteredProperties = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor prop in properties) { FilterPropertiesEventArgs args = new FilterPropertiesEventArgs(prop); Config.ReportSettings.OnFilterBusinessObjectProperties(source.DataSource, args); if (!args.Skip) { filteredProperties.Add(args.Property); } } if (instance is IDisposable) { try { (instance as IDisposable).Dispose(); } catch { } } return(filteredProperties); } }
private PropertyDescriptorCollection GetProperties(Column column) { using (BindingSource source = new BindingSource()) { source.DataSource = column.Reference != null ? column.Reference : column.DataType; PropertyDescriptorCollection properties = source.GetItemProperties(null); PropertyDescriptorCollection filteredProperties = new PropertyDescriptorCollection(null); foreach (PropertyDescriptor prop in properties) { FilterPropertiesEventArgs args = new FilterPropertiesEventArgs(prop); Config.ReportSettings.OnFilterBusinessObjectProperties(source.DataSource, args); if (!args.Skip) { filteredProperties.Add(args.Property); } } return(filteredProperties); } }