Skip to content

Commit 22a6ff9

Browse files
authored
Merge pull request #15 from ioaznnis/upgrade-to-AutoMapper-12
Changed reference to AutoMapper to the range [12.0, 13.0)
2 parents cbed4d8 + 7a3b374 commit 22a6ff9

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/AutoMapper.Extensions.EnumMapping/AutoMapper.Extensions.EnumMapping.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="AutoMapper" Version="[11.0, 12.0)" />
29+
<PackageReference Include="AutoMapper" Version="[12.0, 13.0)" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

src/AutoMapper.Extensions.EnumMapping/EnumMapperConfigurationExpressionExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ public static void EnableEnumMappingValidation(this IMapperConfigurationExpressi
1919
{
2020
if (context.TypeMap != null)
2121
{
22-
var validator = context.TypeMap.Features.OfType<IEnumMappingValidationRuntimeFeature>().SingleOrDefault();
23-
validator?.Validate(context.TypeMap.Types);
22+
foreach (var feature in context.TypeMap.Features)
23+
{
24+
if (feature is IEnumMappingValidationRuntimeFeature validator)
25+
{
26+
validator.Validate(context.TypeMap.Types);
27+
}
28+
}
2429
}
2530
});
2631
}

src/AutoMapper.Extensions.EnumMapping/Internal/EnumMappingFeature.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using AutoMapper.Execution;
45
using AutoMapper.Features;
56

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

24-
if (!typeMap.DestinationTypeToUse.IsEnum)
25+
if (!typeMap.DestinationType.IsEnum)
2526
{
26-
throw new ArgumentException($"The type {typeMap.DestinationTypeToUse.FullName} can not be configured as an Enum, because it is not an Enum");
27+
throw new ArgumentException($"The type {typeMap.DestinationType.FullName} can not be configured as an Enum, because it is not an Enum");
2728
}
2829

29-
var enumValueMappings = CreateOverridedEnumValueMappings(typeMap.SourceType, typeMap.DestinationTypeToUse);
30+
var enumValueMappings = CreateOverridedEnumValueMappings(typeMap.SourceType, typeMap.DestinationType);
3031

31-
typeMap.CustomMapExpression = new CustomMapExpressionFactory<TSource, TDestination>(enumValueMappings).Create();
32+
var lambdaExpression = new CustomMapExpressionFactory<TSource, TDestination>(enumValueMappings).Create();
33+
typeMap.TypeConverter = new ExpressionTypeConverter(lambdaExpression);
3234
typeMap.Features.Set(new EnumMappingValidationRuntimeFeature<TSource, TDestination>(enumValueMappings, EnumMappingType));
3335
}
3436

0 commit comments

Comments
 (0)