Skip to content

Commit

Permalink
Fix MapsterMapper#370 where capitalized abbreviations are not mapped …
Browse files Browse the repository at this point in the history
…properly between records
  • Loading branch information
joshua-clark-perenso committed May 21, 2023
1 parent 862bc8b commit 5cf7259
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/Mapster.Tests/WhenMappingRecordTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public void Map_RecordType()
dest.Age.ShouldBe(10);
}

[TestMethod]
public void Map_RecordType_CapitalizationChanged()
{
TypeAdapterConfig<RecordType, RecordTypeDto>.NewConfig()
.Map(dest => dest.SpecialID, src => src.Id)
.Compile();

var source = new RecordType(Guid.NewGuid(), DayOfWeek.Monday);
var dest = source.Adapt<RecordTypeDto>();

dest.SpecialID.ShouldBe(source.Id);
}

public class SimplePoco
{
public Guid Id { get; set; }
Expand All @@ -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)
{
Expand All @@ -64,5 +77,10 @@ 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
);
}
}
2 changes: 1 addition & 1 deletion src/Mapster/Settings/ValueAccessingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5cf7259

Please sign in to comment.