Skip to content

Commit 7a3b374

Browse files
committed
Set CustomMapExpression over TypeConverter
1 parent 8eb3e89 commit 7a3b374

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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.Get<IEnumMappingValidationRuntimeFeature>();
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: 3 additions & 1 deletion
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
@@ -28,7 +29,8 @@ public void Configure(TypeMap typeMap)
2829

2930
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)