Skip to content

Commit

Permalink
Enums do not require type maps. (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaiseD authored Jan 25, 2023
1 parent 2768e95 commit c5c1a1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/AutoMapper.Extensions.ExpressionMapping/TypeMapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void Map_expression_with_constant_list_using_generic_list_dot_contains()
cfg =>
{
cfg.CreateMap<EntityModel, Entity>();
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
}
);
config.AssertConfigurationIsValid();
Expand Down Expand Up @@ -79,7 +78,6 @@ public void Map_expression_with_constant_list_using_generic_enumerable_dot_conta
cfg =>
{
cfg.CreateMap<EntityModel, Entity>();
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
}
);
config.AssertConfigurationIsValid();
Expand Down Expand Up @@ -110,7 +108,6 @@ public void Map_expression_with_constant_dictionary()
cfg =>
{
cfg.CreateMap<EntityModel, Entity>();
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
}
);
config.AssertConfigurationIsValid();
Expand Down Expand Up @@ -142,7 +139,6 @@ public void Map_expression_with_constant_dictionary_mapping_both_Key_and_value()
{
cfg.CreateMap<EntityModel, Entity>();
cfg.CreateMap<Entity, EntityModel>();
cfg.CreateMap<SimpleEnum, SimpleEnumModel>();
}
);
config.AssertConfigurationIsValid();
Expand Down

0 comments on commit c5c1a1d

Please sign in to comment.