Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="[11.0, 12.0)" />
<PackageReference Include="AutoMapper" Version="[12.0, 13.0)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ public static void EnableEnumMappingValidation(this IMapperConfigurationExpressi
{
if (context.TypeMap != null)
{
var validator = context.TypeMap.Features.OfType<IEnumMappingValidationRuntimeFeature>().SingleOrDefault();
validator?.Validate(context.TypeMap.Types);
foreach (var feature in context.TypeMap.Features)
{
if (feature is IEnumMappingValidationRuntimeFeature validator)
{
validator.Validate(context.TypeMap.Types);
}
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AutoMapper.Execution;
using AutoMapper.Features;

namespace AutoMapper.Extensions.EnumMapping.Internal
Expand All @@ -21,14 +22,15 @@ public void Configure(TypeMap typeMap)
throw new ArgumentException($"The type {typeMap.SourceType.FullName} can not be configured as an Enum, because it is not an Enum");
}

if (!typeMap.DestinationTypeToUse.IsEnum)
if (!typeMap.DestinationType.IsEnum)
{
throw new ArgumentException($"The type {typeMap.DestinationTypeToUse.FullName} can not be configured as an Enum, because it is not an Enum");
throw new ArgumentException($"The type {typeMap.DestinationType.FullName} can not be configured as an Enum, because it is not an Enum");
}

var enumValueMappings = CreateOverridedEnumValueMappings(typeMap.SourceType, typeMap.DestinationTypeToUse);
var enumValueMappings = CreateOverridedEnumValueMappings(typeMap.SourceType, typeMap.DestinationType);

typeMap.CustomMapExpression = new CustomMapExpressionFactory<TSource, TDestination>(enumValueMappings).Create();
var lambdaExpression = new CustomMapExpressionFactory<TSource, TDestination>(enumValueMappings).Create();
typeMap.TypeConverter = new ExpressionTypeConverter(lambdaExpression);
typeMap.Features.Set(new EnumMappingValidationRuntimeFeature<TSource, TDestination>(enumValueMappings, EnumMappingType));
}

Expand Down