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
7 changes: 4 additions & 3 deletions src/AutoMapper/ProfileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ private void AddMemberMaps(LambdaExpression[] includedMembers, TypeMap mainMap,

private void ApplyDerivedMaps(TypeMap baseMap, TypeMap typeMap, IConfigurationProvider configurationProvider)
{
foreach (var inheritedTypeMap in configurationProvider.GetIncludedTypeMaps(typeMap.IncludedDerivedTypes))
foreach (var derivedMap in configurationProvider.GetIncludedTypeMaps(typeMap.IncludedDerivedTypes))
{
inheritedTypeMap.IncludeBaseTypes(typeMap.SourceType, typeMap.DestinationType);
ApplyDerivedMaps(baseMap, inheritedTypeMap, configurationProvider);
derivedMap.IncludeBaseTypes(typeMap.SourceType, typeMap.DestinationType);
derivedMap.AddInheritedMap(baseMap);
ApplyDerivedMaps(baseMap, derivedMap, configurationProvider);
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/UnitTests/MappingInheritance/IgnoreShouldBeInherited.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@

namespace AutoMapper.UnitTests.Bug
{
public class IgnoreShouldBeInheritedRegardlessOfMapOrder : AutoMapperSpecBase
{
public class BaseDomain
{
}

public class SpecificDomain : BaseDomain
{
public string SpecificProperty { get; set; }
}

public class Dto
{
public string SpecificProperty { get; set; }
}

protected override MapperConfiguration Configuration => new MapperConfiguration(cfg =>
{
cfg.CreateMap<SpecificDomain, Dto>();
cfg.CreateMap<BaseDomain, Dto>()
.ForMember(d => d.SpecificProperty, m => m.Ignore())
.Include<SpecificDomain, Dto>();
});

[Fact]
public void Should_map_ok()
{
var dto = Mapper.Map<Dto>(new SpecificDomain { SpecificProperty = "Test" });
dto.SpecificProperty.ShouldBeNull();
}
}

public class IgnoreShouldBeInherited : AutoMapperSpecBase
{
public class BaseDomain
Expand Down