File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ public void Configure(TypeMap typeMap)
130130 var destMember = DestinationMember ;
131131 if ( destMember . DeclaringType . ContainsGenericParameters )
132132 {
133- destMember = typeMap . DestinationSetters . Single ( m => m . Name == destMember . Name ) ;
133+ destMember = Array . Find ( typeMap . DestinationTypeDetails . ReadAccessors , m => m . MetadataToken == destMember . MetadataToken ) ;
134134 }
135135 var propertyMap = typeMap . FindOrCreatePropertyMapFor ( destMember , typeof ( TMember ) == typeof ( object ) ? destMember . GetMemberType ( ) : typeof ( TMember ) ) ;
136136 Apply ( propertyMap ) ;
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ internal bool CanConstructorMap() => Profile.ConstructorMappingEnabled && !Desti
6565 public TypePair Types ;
6666 public ConstructorMap ConstructorMap { get ; set ; }
6767 public TypeDetails SourceTypeDetails { get ; private set ; }
68- private TypeDetails DestinationTypeDetails { get ; set ; }
68+ public TypeDetails DestinationTypeDetails { get ; private set ; }
6969 public Type SourceType => Types . SourceType ;
7070 public Type DestinationType => Types . DestinationType ;
7171 public ProfileMap Profile { get ; }
Original file line number Diff line number Diff line change 11namespace AutoMapper . UnitTests ;
2+ public class ReadonlyPropertiesGenerics : AutoMapperSpecBase
3+ {
4+ class Source
5+ {
6+ public InnerSource Inner ;
7+ }
8+ class InnerSource
9+ {
10+ public int Value ;
11+ }
12+ class Destination < T >
13+ {
14+ public readonly InnerDestination Inner = new ( ) ;
15+ }
16+ class InnerDestination
17+ {
18+ public int Value ;
19+ }
20+ protected override MapperConfiguration CreateConfiguration ( ) => new ( c =>
21+ {
22+ c . CreateMap ( typeof ( Source ) , typeof ( Destination < > ) ) . ForMember ( "Inner" , o => o . MapFrom ( "Inner" ) ) ;
23+ c . CreateMap < InnerSource , InnerDestination > ( ) ;
24+ } ) ;
25+ [ Fact ]
26+ public void Should_work ( ) => Map < Destination < int > > ( new Source { Inner = new ( ) { Value = 42 } } ) . Inner . Value . ShouldBe ( 42 ) ;
27+ }
228public class ConstructorValidationGenerics : NonValidatingSpecBase
329{
430 record Source < T > ( T Value ) ;
You can’t perform that action at this time.
0 commit comments