C#C
C#4y ago
florent

Generics and type inference

    public TDest MapTo<TSource, TDest>(TSource src)
    {
        var res = _mapper.Map<TSource, TDest>(src);
        return res; 
    }

Why can't the compiler infer my type of TSource? If I call that mehod I always have to specify it like this
Mapper.MapTo<ObjectA, ObjectB>(instance of ObjectA); 
It should be possible to call it just like this
Mapper.MapTo<ObjectB>(instance of ObjectA);
I am just starting with .NET
Was this page helpful?