Skip to content

Automapper 12 and custom Enum Type Conveter #4230

@shalinparmar

Description

@shalinparmar

Source/destination types

public 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.z

Automapper 12.0.1

Expected behavior

Actual behavior

System.ArgumentException
Expression of type 'System.Enum' cannot be used for assignment to type 'xxx.Model.Enums.LicenceType'
at System.Linq.Expressions.Expression.Assign(Expression left, Expression right)
at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(MemberMap memberMap, Expression destination, MemberInfo destinationMember)
at AutoMapper.Execution.TypeMapPlanBuilder.AddPropertyMaps(List1 actions) at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(Expression createDestination) at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda() at AutoMapper.TypeMap.CreateMapperLambda(IGlobalConfiguration configuration) at AutoMapper.TypeMap.Seal(IGlobalConfiguration configuration) at AutoMapper.MapperConfiguration.<.ctor>g__Seal|20_0() at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression) at AutoMapper.MapperConfiguration..ctor(Action1 configure)

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions