public IEnumerable <object> GetObjects(IDataSource dataSource) { List <object> retval = new List <object>(); var classMap = MapRegistrar.MappedClasses[Type]; while (dataSource.Read()) { var createdObject = Type.GetConstructor(Type.EmptyTypes).Invoke(null); foreach (var property in classMap.MappedProperties) { object dataValue = null; if (MapRegistrar.MappedClasses.ContainsKey(property.PropertyInfo.PropertyType)) { dataValue = new TypeObjectCreator(property.PropertyInfo.PropertyType).GetObject(dataSource); } else { dataValue = dataSource[classMap.PrefixName + property.ColumnName]; } if (dataValue != null) { property.PropertyInfo.SetValue(createdObject, dataValue); } } retval.Add(createdObject); } return(retval); }
public object GetObject(IDataSource dataSource) { var classMap = MapRegistrar.MappedClasses[Type]; var createdObject = Type.GetConstructor(Type.EmptyTypes).Invoke(null); foreach (var property in classMap.MappedProperties) { object dataValue = null; if (MapRegistrar.MappedClasses.ContainsKey(property.PropertyInfo.PropertyType)) { dataValue = new TypeObjectCreator(property.PropertyInfo.PropertyType).GetObject(dataSource); } else { dataValue = Convert.ChangeType( dataSource[classMap.PrefixName + property.ColumnName], property.PropertyInfo.PropertyType); } if (dataValue != null) { property.PropertyInfo.SetValue(createdObject, dataValue); } } return(createdObject); }