Call to DataMapper resolves to generic method - even when no generics are specified!!!

Call to DataMapper resolves to generic method - even when no generics are specified!!!

Old forum URL: forums.lhotka.net/forums/t/7311.aspx


SonOfPirate posted on Tuesday, July 21, 2009

I have my own version of the DataMapper class that includes generic methods such as:

public static void Map<TSource, TTarget>(TSource source, TTarget target) { ... }

In my web page, I am using an CslaDataSource and handling the UpdateObject event.  I pass the e.Values property as the source to DataMapper.Map as follows:

DataMapper.Map(e.Value, myBO);

I would expect the call to resolve to the:

public static void Map(System.Collections.IDictionary source, System.Object target)

method but instead it goes to the generic method.  Any ideas why this would be the case?  I am not specifying the generic types in my call, so why would the compiler direct the call to the generic version?

 

RockfordLhotka replied on Tuesday, July 21, 2009

I would guess that the compiler is using type inference and is finding that the generic method is a closer match based on the parameter types. Perhaps the compiler team gave preference to generic matches over looser matches with the assumption you'd want strong typing when possible?

Copyright (c) Marimer LLC