Skip to content

Commit

Permalink
Merge pull request #590 from joshslark/master
Browse files Browse the repository at this point in the history
Fix #370 where capitalized abbreviations are not mapped …
  • Loading branch information
andrerav authored May 29, 2023
2 parents c2d370f + 45d012e commit cc81763
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 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,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);
}
}
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 cc81763

Please sign in to comment.