Automapper 12 and custom Enum Type Converter #4231
-
https://gist.github.com/shalinparmar/8be92a90b45cc592abc8df82a3ea9a35 Source/destination typespublic class EnumTypeConverter<TValue,TEnum> : ITypeConverter<TValue, TEnum> Mapping configuration// Mapper.Initialize or just the CreateMap snippet
CreateMap<string, Enum>().ConvertUsing<EnumTypeConverter<string, Enum>>();
CreateMap<decimal?, Enum>().ConvertUsing<EnumTypeConverter<decimal?, Enum>>();
CreateMap<int, Enum>().ConvertUsing<EnumTypeConverter<int, Enum>>(); Version: x.y.zAutomapper 12.0.1 Expected behaviorActual behaviorSystem.ArgumentException Steps to reproduce// Your calls to Mapper.Map or ProjectTo here, with source/destination objects constructed .ForMember(d => d.Type, opt => opt.MapFrom(s => s.LicenceType)) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
A value converter fits better here. Or you can workaround it using the context mapper. But we'll add that cast :) |
Beta Was this translation helpful? Give feedback.
A value converter fits better here. Or you can workaround it using the context mapper. But we'll add that cast :)
Try the MyGet build.