From 45d012e00ce972cf2ba33fb54bebe22509903479 Mon Sep 17 00:00:00 2001 From: joshslark Date: Sat, 20 May 2023 20:35:18 -0500 Subject: [PATCH] Fix MapsterMapper#370 where capitalized abbreviations are not mapped properly between records --- src/Mapster.Tests/WhenMappingRecordTypes.cs | 17 ++++++++++++++++- src/Mapster/Settings/ValueAccessingStrategy.cs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Mapster.Tests/WhenMappingRecordTypes.cs b/src/Mapster.Tests/WhenMappingRecordTypes.cs index 686f92f5..b855c354 100644 --- a/src/Mapster.Tests/WhenMappingRecordTypes.cs +++ b/src/Mapster.Tests/WhenMappingRecordTypes.cs @@ -37,6 +37,19 @@ public void Map_RecordType() dest.Age.ShouldBe(10); } + [TestMethod] + public void Map_RecordType_CapitalizationChanged() + { + TypeAdapterConfig.NewConfig() + .Map(dest => dest.SpecialID, src => src.Id) + .Compile(); + + var source = new RecordType(Guid.NewGuid(), DayOfWeek.Monday); + var dest = source.Adapt(); + + dest.SpecialID.ShouldBe(source.Id); + } + public class SimplePoco { public Guid Id { get; set; } @@ -49,7 +62,7 @@ public class SimpleDto public string Name { get; set; } } - public class RecordType + public record RecordType { public RecordType(Guid id, DayOfWeek day, string name = "foo", int age = 10) { @@ -64,5 +77,7 @@ public RecordType(Guid id, DayOfWeek day, string name = "foo", int age = 10) public int Age { get; } public DayOfWeek Day { get; } } + + public record RecordTypeDto(Guid SpecialID); } } diff --git a/src/Mapster/Settings/ValueAccessingStrategy.cs b/src/Mapster/Settings/ValueAccessingStrategy.cs index 29e6e443..ea47d9ad 100644 --- a/src/Mapster/Settings/ValueAccessingStrategy.cs +++ b/src/Mapster/Settings/ValueAccessingStrategy.cs @@ -36,7 +36,7 @@ public static class ValueAccessingStrategy Expression? getter = null; foreach (var resolver in resolvers) { - if (!destinationMember.Name.Equals(resolver.DestinationMemberName)) + if (!destinationMember.Name.Equals(resolver.DestinationMemberName, StringComparison.InvariantCultureIgnoreCase)) continue; var invoke = resolver.GetInvokingExpression(source, arg.MapType);