diff --git a/src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs b/src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs index 65df684..de99e10 100644 --- a/src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs +++ b/src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs @@ -28,9 +28,14 @@ public static bool CanMapConstant(this IConfigurationProvider config, Type sourc return config.CanMapConstant(sourceType.GetElementType(), destType.GetElementType()); else if (BothTypesAreEnumerable()) return config.CanMapConstant(sourceType.GetGenericArguments()[0], destType.GetGenericArguments()[0]); + else if (BothTypesAreEnums()) + return true; else return config.Internal().ResolveTypeMap(sourceType, destType) != null; + bool BothTypesAreEnums() + => sourceType.IsEnum && destType.IsEnum; + bool BothTypesAreEnumerable() { Type enumerableType = typeof(System.Collections.IEnumerable); diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs index 8573476..c1ab754 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs @@ -48,7 +48,6 @@ public void Map_expression_with_constant_list_using_generic_list_dot_contains() cfg => { cfg.CreateMap(); - cfg.CreateMap(); } ); config.AssertConfigurationIsValid(); @@ -79,7 +78,6 @@ public void Map_expression_with_constant_list_using_generic_enumerable_dot_conta cfg => { cfg.CreateMap(); - cfg.CreateMap(); } ); config.AssertConfigurationIsValid(); @@ -110,7 +108,6 @@ public void Map_expression_with_constant_dictionary() cfg => { cfg.CreateMap(); - cfg.CreateMap(); } ); config.AssertConfigurationIsValid(); @@ -142,7 +139,6 @@ public void Map_expression_with_constant_dictionary_mapping_both_Key_and_value() { cfg.CreateMap(); cfg.CreateMap(); - cfg.CreateMap(); } ); config.AssertConfigurationIsValid();