public IList <T> ToObjects <T>(DataRow[] dataRows, IDataTypeConverter dataTypeConverter, ExtendedPropertyInfo[] mappings, DataTableParserSettings settings) { Guard.ArgumentNotNull(dataRows); Guard.ArgumentNotNull(dataTypeConverter); Guard.ArgumentNotNull(mappings); Guard.ArgumentNotNull(settings); List <T> objectList = new List <T>(capacity: dataRows.Length); var dbNullConverter = new DbNullConverter(settings); IEnumerable <DelegateColumnMapping <T> > delegates = GetDelegatesForType <T>(mappings); for (int rowIndex = 0; rowIndex < dataRows.Length; rowIndex++) { T returnObject = ObjectInstantiator <T> .CreateNew(); foreach (var setterDelegate in delegates) { object value = dataTypeConverter.FieldToObject(dataRows[rowIndex][setterDelegate.ExtendedPropertyInfo.ColumnIndex], setterDelegate.ExtendedPropertyInfo.PropertyInfo.PropertyType, settings, dbNullConverter); setterDelegate.SetterDelegate(returnObject, value); } objectList.Add(returnObject); } return(objectList); }
public virtual IList <T> ToObjects <T>(DataRow[] dataRows, IDataTypeConverter dataTypeConverter, ExtendedPropertyInfo[] mappings, DataTableParserSettings settings) { Guard.ArgumentNotNull(dataRows); Guard.ArgumentNotNull(dataTypeConverter); Guard.ArgumentNotNull(mappings); Guard.ArgumentNotNull(settings); var dbNullConverter = GetDbNullConverter(settings); var objectList = new T[dataRows.Length]; for (int rowIndex = 0; rowIndex < dataRows.Length; rowIndex++) { var returnObject = ObjectInstantiator <T> .CreateNew(); foreach (var mapping in mappings) { object value = dataTypeConverter.FieldToObject(dataRows[rowIndex][mapping.ColumnIndex], mapping.PropertyInfo.PropertyType, settings, dbNullConverter); mapping.PropertyInfo.SetValue(returnObject, value); } objectList[rowIndex] = returnObject; } return(objectList); }
public IList <T> ToObjects <T>(DataRow[] dataRows, IDataTypeConverter dataTypeConverter, ExtendedPropertyInfo[] mappings, DataTableParserSettings settings) { Guard.ArgumentNotNull(dataRows); Guard.ArgumentNotNull(dataTypeConverter); Guard.ArgumentNotNull(mappings); Guard.ArgumentNotNull(settings); ConcurrentBag <T> objectList = new ConcurrentBag <T>(); var dbNullConverter = new DbNullConverter(settings); Parallel.For(0, dataRows.Length, (rowIndex) => { T returnObject = ObjectInstantiator <T> .CreateNew(); foreach (var mapping in mappings) { object value = dataTypeConverter.FieldToObject(dataRows[rowIndex][mapping.ColumnIndex], mapping.PropertyInfo.PropertyType, settings, dbNullConverter); mapping.PropertyInfo.SetValue(returnObject, value); } objectList.Add(returnObject); }); return(objectList.ToList()); }
private object GetAssertObject <T>(object field) { return(dataTypeConverter.FieldToObject(field, typeof(T), dataTableParserSettings, new DbNullConverter(dataTableParserSettings))); }