File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
AgileMapper.UnitTests/Configuration Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -860,5 +860,40 @@ public void ShouldRestrictConfigurationApplicationByMappingRuleSet()
860860 overwriteResult . Value . ShouldBe ( source . Value ) ;
861861 }
862862 }
863+
864+ // See https://github.com/agileobjects/AgileMapper/issues/14
865+ [ Fact ]
866+ public void ShouldAllowIdAndIdentifierConfiguration ( )
867+ {
868+ using ( var mapper = Mapper . CreateNew ( ) )
869+ {
870+ mapper . WhenMapping
871+ . From < PublicTwoFields < int , int > > ( )
872+ . To < IdTester > ( )
873+ . Map ( ( ptf , id ) => ptf . Value1 )
874+ . To ( id => id . ClassId )
875+ . And
876+ . Map ( ( ptf , id ) => ptf . Value2 )
877+ . To ( id => id . ClassIdentifier ) ;
878+
879+ var source = new PublicTwoFields < int , int >
880+ {
881+ Value1 = 123 ,
882+ Value2 = 987
883+ } ;
884+
885+ var result = mapper . Map ( source ) . ToANew < IdTester > ( ) ;
886+
887+ result . ClassId . ShouldBe ( 123 ) ;
888+ result . ClassIdentifier . ShouldBe ( 987 ) ;
889+ }
890+ }
891+
892+ private class IdTester
893+ {
894+ public int ClassId { get ; set ; }
895+
896+ public int ClassIdentifier { get ; set ; }
897+ }
863898 }
864899}
Original file line number Diff line number Diff line change @@ -55,12 +55,15 @@ public virtual bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem)
5555
5656 if ( ConfigInfo . HasCompatibleTypes ( otherConfiguredItem . ConfigInfo ) )
5757 {
58- return TargetMember . Matches ( otherConfiguredItem . TargetMember ) ;
58+ return MembersConflict ( otherConfiguredItem . TargetMember ) ;
5959 }
6060
6161 return false ;
6262 }
6363
64+ protected virtual bool MembersConflict ( QualifiedMember otherMember )
65+ => TargetMember . Matches ( otherMember ) ;
66+
6467 protected bool SourceAndTargetTypesAreTheSame ( UserConfiguredItemBase otherConfiguredItem )
6568 {
6669 return ConfigInfo . HasSameSourceTypeAs ( otherConfiguredItem . ConfigInfo ) &&
Original file line number Diff line number Diff line change 11namespace AgileObjects . AgileMapper . DataSources
22{
3+ using System . Linq ;
34 using System . Linq . Expressions ;
45 using Configuration ;
56 using Members ;
@@ -48,6 +49,9 @@ public override bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem)
4849 return _dataSourceLambda . IsSameAs ( otherDataSource . _dataSourceLambda ) ;
4950 }
5051
52+ protected override bool MembersConflict ( QualifiedMember otherMember )
53+ => TargetMember . LeafMember . Equals ( otherMember . LeafMember ) ;
54+
5155 public IConfiguredDataSource Create ( IMemberMapperData mapperData )
5256 {
5357 var configuredCondition = GetConditionOrNull ( mapperData ) ;
You can’t perform that action at this time.
0 commit comments