public ProductImageInfo GetImgWithKey(int pi_id) { ProductImageInfo info = new Model.ProductImageInfo(); IDataReader reader = db.GetImageWithKey(pi_id).CreateDataReader(); if (reader.Read()) { info = ProductImageInfo.Populate(reader); } return(info); }
public static ProductImageInfo Populate(IDataReader reader) { ProductImageInfo info = new ProductImageInfo(); for (int i = 0; i < reader.FieldCount; i++) { PropertyInfo property = info.GetType().GetProperty(reader.GetName(i)); Type propType = property.PropertyType; TypeConverters.ITypeConverter typeConverter = TypeConverters.TypeConverterFactory.GetConvertType(propType); property.SetValue(info, Convert.ChangeType(typeConverter.Convert(reader.GetValue(i)), propType), null); } return(info); }