Skip to content

Commit c5c1a1d

Browse files
authored
Enums do not require type maps. (#160)
1 parent 2768e95 commit c5c1a1d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ public static bool CanMapConstant(this IConfigurationProvider config, Type sourc
2828
return config.CanMapConstant(sourceType.GetElementType(), destType.GetElementType());
2929
else if (BothTypesAreEnumerable())
3030
return config.CanMapConstant(sourceType.GetGenericArguments()[0], destType.GetGenericArguments()[0]);
31+
else if (BothTypesAreEnums())
32+
return true;
3133
else
3234
return config.Internal().ResolveTypeMap(sourceType, destType) != null;
3335

36+
bool BothTypesAreEnums()
37+
=> sourceType.IsEnum && destType.IsEnum;
38+
3439
bool BothTypesAreEnumerable()
3540
{
3641
Type enumerableType = typeof(System.Collections.IEnumerable);

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public void Map_expression_with_constant_list_using_generic_list_dot_contains()
4848
cfg =>
4949
{
5050
cfg.CreateMap<EntityModel, Entity>();
51-
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
5251
}
5352
);
5453
config.AssertConfigurationIsValid();
@@ -79,7 +78,6 @@ public void Map_expression_with_constant_list_using_generic_enumerable_dot_conta
7978
cfg =>
8079
{
8180
cfg.CreateMap<EntityModel, Entity>();
82-
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
8381
}
8482
);
8583
config.AssertConfigurationIsValid();
@@ -110,7 +108,6 @@ public void Map_expression_with_constant_dictionary()
110108
cfg =>
111109
{
112110
cfg.CreateMap<EntityModel, Entity>();
113-
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
114111
}
115112
);
116113
config.AssertConfigurationIsValid();
@@ -142,7 +139,6 @@ public void Map_expression_with_constant_dictionary_mapping_both_Key_and_value()
142139
{
143140
cfg.CreateMap<EntityModel, Entity>();
144141
cfg.CreateMap<Entity, EntityModel>();
145-
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
146142
}
147143
);
148144
config.AssertConfigurationIsValid();

0 commit comments

Comments
 (0)