I was trying to create a generic method to read column values from a datarow using the datarowextension methods:
public static Nullable<T> SafeRead<T>(DataRow row, string fieldName) where T : struct
{
if (row.HasColumn(fieldName))
{
return row.Field<Nullable<T>>(fieldName) ?? default(Nullable<T>);
}
else
return default(Nullable<T>);
}
public static T SafeRead<T>(DataRow row, string fieldName) where T : class
{
if (row.HasColumn(fieldName))
{
return row.Field<T>(fieldName) ?? default(T);
}
else
return default(T);
}
When I call this function from my code the compiler complains that there is an ambiguous reference between the two calls which is obvious when I look at the method signatures. However, I am not sure how to handle this without using separate methods.
The return value is not part of the identifying method signature. So your methods look like this to the compiler:
and
-> There is no difference.
you should rename one of the methods.