public NewsImageInfo GetImgWithKey(int np_id) { NewsImageInfo info = new Model.NewsImageInfo(); IDataReader reader = db.GetImageWithKey(np_id).CreateDataReader(); if (reader.Read()) { info = NewsImageInfo.Populate(reader); } return(info); }
public static NewsImageInfo Populate(IDataReader reader) { NewsImageInfo info = new NewsImageInfo(); 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); }