1
Vote

Questionable DataRowExtensions behavior

description

Let's have a look at one of the extension methods:
public static int GetInt32(this DataRow row, string field, int defaultValue)
{
    var value = row[field];
    return (value is int ? (int) value : defaultValue);
}
The problem with this method is that the data source column MUST be an int column, otherwise the default value is returned with no error. Therefore, if data column type changes, the method will not even try to convert the value to an integer.

I see it being implemented in the following manner:
public static int GetInt32(this DataRow row, string field, int defaultValue)
{
    return row.Get<int>(field, defaultValue);
}

comments

ruslancanada wrote May 23, 2013 at 9:39 PM

DataReaderExtensions behave in similar method, which I would recommend fixing as well.