diff --git a/AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs b/AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs index e7bfe4bab..bfb50364a 100644 --- a/AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs +++ b/AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs @@ -860,5 +860,40 @@ public void ShouldRestrictConfigurationApplicationByMappingRuleSet() overwriteResult.Value.ShouldBe(source.Value); } } + + // See https://github.com/agileobjects/AgileMapper/issues/14 + [Fact] + public void ShouldAllowIdAndIdentifierConfiguration() + { + using (var mapper = Mapper.CreateNew()) + { + mapper.WhenMapping + .From>() + .To() + .Map((ptf, id) => ptf.Value1) + .To(id => id.ClassId) + .And + .Map((ptf, id) => ptf.Value2) + .To(id => id.ClassIdentifier); + + var source = new PublicTwoFields + { + Value1 = 123, + Value2 = 987 + }; + + var result = mapper.Map(source).ToANew(); + + result.ClassId.ShouldBe(123); + result.ClassIdentifier.ShouldBe(987); + } + } + + private class IdTester + { + public int ClassId { get; set; } + + public int ClassIdentifier { get; set; } + } } } diff --git a/AgileMapper/Configuration/UserConfiguredItemBase.cs b/AgileMapper/Configuration/UserConfiguredItemBase.cs index 262b07112..972b7f8f6 100644 --- a/AgileMapper/Configuration/UserConfiguredItemBase.cs +++ b/AgileMapper/Configuration/UserConfiguredItemBase.cs @@ -55,12 +55,15 @@ public virtual bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem) if (ConfigInfo.HasCompatibleTypes(otherConfiguredItem.ConfigInfo)) { - return TargetMember.Matches(otherConfiguredItem.TargetMember); + return MembersConflict(otherConfiguredItem.TargetMember); } return false; } + protected virtual bool MembersConflict(QualifiedMember otherMember) + => TargetMember.Matches(otherMember); + protected bool SourceAndTargetTypesAreTheSame(UserConfiguredItemBase otherConfiguredItem) { return ConfigInfo.HasSameSourceTypeAs(otherConfiguredItem.ConfigInfo) && diff --git a/AgileMapper/DataSources/ConfiguredDataSourceFactory.cs b/AgileMapper/DataSources/ConfiguredDataSourceFactory.cs index e6ff79a5f..2e7a230a1 100644 --- a/AgileMapper/DataSources/ConfiguredDataSourceFactory.cs +++ b/AgileMapper/DataSources/ConfiguredDataSourceFactory.cs @@ -1,5 +1,6 @@ namespace AgileObjects.AgileMapper.DataSources { + using System.Linq; using System.Linq.Expressions; using Configuration; using Members; @@ -48,6 +49,9 @@ public override bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem) return _dataSourceLambda.IsSameAs(otherDataSource._dataSourceLambda); } + protected override bool MembersConflict(QualifiedMember otherMember) + => TargetMember.LeafMember.Equals(otherMember.LeafMember); + public IConfiguredDataSource Create(IMemberMapperData mapperData) { var configuredCondition = GetConditionOrNull(mapperData);