From c5c1a1df65ccfdbdb0c9922a78da85103533420c Mon Sep 17 00:00:00 2001 From: Blaise Taylor Date: Wed, 25 Jan 2023 06:22:28 -0500 Subject: [PATCH] Enums do not require type maps. (#160) --- src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs | 5 +++++ .../CanMapExpressionWithListConstants.cs | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) 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();