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
2 changes: 1 addition & 1 deletion src/AutoMapper/ProfileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void Configure(IGlobalConfiguration configuration)
}
private void Configure(TypeMapConfiguration typeMapConfiguration, IGlobalConfiguration configuration)
{
var typeMap = typeMapConfiguration.TypeMap;
var typeMap = configuration.FindTypeMapFor(typeMapConfiguration.Types);
if (typeMap.IncludeAllDerivedTypes)
{
IncludeAllDerived(configuration, typeMap);
Expand Down
40 changes: 40 additions & 0 deletions src/UnitTests/Bug/OpenGenericInheritanceOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace AutoMapper.UnitTests.Bug;

public class OpenGenericInheritanceOrder
{
class FooBar { }
class SourceBase<T> { public string Name { get; set; } }
class DestinationBase { public string Name { get; set; } }
class SourceDerived : SourceBase<FooBar> { }
class DestinationDerived : DestinationBase { }

[Fact]
public void Should_work_when_derived_map_declared_before_open_generic_base_map()
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<SourceDerived, DestinationDerived>()
.IncludeBase<SourceBase<FooBar>, DestinationBase>();
cfg.CreateMap(typeof(SourceBase<>), typeof(DestinationBase));
});

var mapper = config.CreateMapper();
var result = mapper.Map<DestinationDerived>(new SourceDerived { Name = "test" });
result.Name.ShouldBe("test");
}

[Fact]
public void Should_work_when_open_generic_base_map_declared_first()
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap(typeof(SourceBase<>), typeof(DestinationBase));
cfg.CreateMap<SourceDerived, DestinationDerived>()
.IncludeBase<SourceBase<FooBar>, DestinationBase>();
});

var mapper = config.CreateMapper();
var result = mapper.Map<DestinationDerived>(new SourceDerived { Name = "test" });
result.Name.ShouldBe("test");
}
}