Mapping Generic<T> to T

Skip to first unread message

Niko Dierickx

Jan 14, 2021, 1:06:37 PM1/14/21
to AutoMapper-users

I'm trying to use Automapper's Open Generics as described in to perform a mapping between Translated<T> and T.

public class Translated<T> 
  public T En { get; set; }
  public T Fr { get; set; } 

I've create a TypeConvertor for it

public class TranslatedConverter<T> : ITypeConverter<Translated<T>, T> 
  public T Convert(Translated<T> source, T destination, ResolutionContext context) 
 { // Conversion logic return source.En; } 

Can somebody help me out how to create a profile for it without specifying the type like in:

CreateMap<Translated<string>, string>().ConvertUsing(new TranslatedConverter<string>());

I'm trying the folowing, but I don't know what to put instead of Type to make in work for all Types

CreateMap(typeof(Translated<>), Type).ConvertUsing(typeof(TranslatedConverter<>));

Reply all
Reply to author
0 new messages