How can I map between two enums using Automapper?
Alternatively to writing custom converters, just use ConvertUsing()
Mapper.CreateMap<EnumSrc, EnumDst>().ConvertUsing((value, destination) =>
{
switch(value)
{
case EnumSrc.Option1:
return EnumDst.Choice1;
case EnumSrc.Option2:
return EnumDst.Choice2;
case EnumSrc.Option3:
return EnumDst.Choice3;
default:
return EnumDst.None;
}
});
You don't need to do CreateMap for enum types. Just get rid of the CreateMap call and it should work, as long as the names and/or values match up between enum types.