Skip to content

Enums do not require type maps. #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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