Skip to content

Commit 2883ae8

Browse files
committed
inherit a MapFrom from an indirect base class
1 parent ed8bb62 commit 2883ae8

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/AutoMapper/TypeMap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ public void Seal(IGlobalConfiguration configuration, TypeMap thisMap)
305305
{
306306
foreach (var inheritedTypeMap in InheritedTypeMaps)
307307
{
308-
var includedMaps = inheritedTypeMap?._details?.IncludedMembersTypeMaps;
308+
inheritedTypeMap.Seal(configuration);
309+
var includedMaps = inheritedTypeMap._details?.IncludedMembersTypeMaps;
309310
if (includedMaps != null)
310311
{
311312
IncludedMembersTypeMaps ??= new();

src/UnitTests/MappingInheritance/IncludedMappingShouldInheritBaseMappings.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
namespace AutoMapper.UnitTests;
2-
2+
public class IncludeBaseIndirectBase : AutoMapperSpecBase
3+
{
4+
public class FooBaseBase
5+
{
6+
}
7+
public class FooBase : FooBaseBase
8+
{
9+
}
10+
public class Foo : FooBase
11+
{
12+
}
13+
public class FooDtoBaseBase
14+
{
15+
public DateTime Date { get; set; }
16+
}
17+
public class FooDtoBase : FooDtoBaseBase
18+
{
19+
}
20+
public class FooDto : FooDtoBase
21+
{
22+
}
23+
protected override MapperConfiguration CreateConfiguration() => new(c =>
24+
{
25+
c.CreateMap<Foo, FooDto>().IncludeBase<FooBase, FooDtoBase>();
26+
c.CreateMap<FooBase, FooDtoBase>().IncludeBase<FooBaseBase, FooDtoBaseBase>();
27+
c.CreateMap<FooBaseBase, FooDtoBaseBase>().ForMember(d => d.Date, o => o.MapFrom(s => DateTime.MaxValue));
28+
});
29+
[Fact]
30+
public void Should_work() => Map<FooDto>(new Foo()).Date.ShouldBe(DateTime.MaxValue);
31+
}
332
public class ReadonlyCollectionPropertiesOverride : AutoMapperSpecBase
433
{
534
protected override MapperConfiguration CreateConfiguration() => new(cfg =>

0 commit comments

Comments
 (0)