File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ public void Configure(IGlobalConfiguration configuration)
168168 }
169169 private void Configure ( TypeMapConfiguration typeMapConfiguration , IGlobalConfiguration configuration )
170170 {
171- var typeMap = typeMapConfiguration . TypeMap ;
171+ var typeMap = configuration . FindTypeMapFor ( typeMapConfiguration . Types ) ?? typeMapConfiguration . TypeMap ;
172172 if ( typeMap . IncludeAllDerivedTypes )
173173 {
174174 IncludeAllDerived ( configuration , typeMap ) ;
Original file line number Diff line number Diff line change 1+ namespace AutoMapper . UnitTests . Bug ;
2+
3+ public class OpenGenericInheritanceOrder
4+ {
5+ class FooBar { }
6+ class SourceBase < T > { public string Name { get ; set ; } }
7+ class DestinationBase { public string Name { get ; set ; } }
8+ class SourceDerived : SourceBase < FooBar > { }
9+ class DestinationDerived : DestinationBase { }
10+
11+ [ Fact ]
12+ public void Should_work_when_derived_map_declared_before_open_generic_base_map ( )
13+ {
14+ var config = new MapperConfiguration ( cfg =>
15+ {
16+ cfg . CreateMap < SourceDerived , DestinationDerived > ( )
17+ . IncludeBase < SourceBase < FooBar > , DestinationBase > ( ) ;
18+ cfg . CreateMap ( typeof ( SourceBase < > ) , typeof ( DestinationBase ) ) ;
19+ } ) ;
20+
21+ var result = config . CreateMapper ( ) . Map < DestinationDerived > ( new SourceDerived { Name = "test" } ) ;
22+ result . Name . ShouldBe ( "test" ) ;
23+ }
24+
25+ [ Fact ]
26+ public void Should_work_when_open_generic_base_map_declared_first ( )
27+ {
28+ var config = new MapperConfiguration ( cfg =>
29+ {
30+ cfg . CreateMap ( typeof ( SourceBase < > ) , typeof ( DestinationBase ) ) ;
31+ cfg . CreateMap < SourceDerived , DestinationDerived > ( )
32+ . IncludeBase < SourceBase < FooBar > , DestinationBase > ( ) ;
33+ } ) ;
34+
35+ var result = config . CreateMapper ( ) . Map < DestinationDerived > ( new SourceDerived { Name = "test" } ) ;
36+ result . Name . ShouldBe ( "test" ) ;
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments