Legion

Legion

  • NA
  • 1
  • 0

Problem with specifying type arguments explicitly when using a delegate

Dec 4 2009 10:40 AM

I get the following compile time error from the code below: Error 1 The type arguments for method 'CompSchemaEngineV2.NullableDataReader.GetNullable<T>(int, CompSchemaEngineV2.NullableDataReader.Conversion<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

I can't figure out whats causing it.  I've tried everything I and my friends can think of and I can't get it to work.  Suggestions?
public int GetInt32(int index)
{
   return sqlReader.GetInt32(index);
}
public Nullable<int> GetNullableInt32(int index)
{
   return GetNullable(index, GetInt32); //This line throws the error
}
private delegate T Conversion<T>(int ordinal);
private Nullable<T> GetNullable<T>(int ordinal,
Conversion<T> convert) where T : struct
{
   Nullable<T> nullable;
   if (sqlReader.IsDBNull(ordinal))
   {
      nullable =
null;
   }
   else
   {
      nullable = convert(ordinal);
   }
   return nullable;
}