matt,
i do a similar type thing with the following in DataAccess.cs:
/// <summary>
/// Cast DBNull using generics
/// </summary>
public static T CastTo<T>(object value)
{
return value != DBNull.Value ? (T)value : default(T);
}
I then in the provider call it as such (in this case the DAL/Provider/SearchProvider.cs):
protected virtual SearchItemEntity GetSearchItemFromReader(IDataReader reader)
{
return new SearchItemEntity(
DataAccess.CastTo<string>(reader["linkID"]),
DataAccess.CastTo<string>(reader["descriptiontext"]),
DataAccess.CastTo<string>(reader["category"]),
DataAccess.CastTo<string>(reader["title"]),
DataAccess.CastTo<string>(reader["source"]),
DataAccess.CastTo<DateTime>(reader["lasteditdate"]));
}
i 'think' this is a similar use of generics to what you're doing above ;)
jimi
http://www.originaltalent.com