diff --git a/src/AutoMapper/Configuration/INamingConvention.cs b/src/AutoMapper/Configuration/INamingConvention.cs index 46e3c93cb..314e85b91 100644 --- a/src/AutoMapper/Configuration/INamingConvention.cs +++ b/src/AutoMapper/Configuration/INamingConvention.cs @@ -24,7 +24,8 @@ public string[] Split(string input) int lower = 0; for(int index = 1; index < input.Length; index++) { - if (char.IsUpper(input[index])) + if (char.IsUpper(input[index]) && + (!char.IsUpper(input[index - 1]) || (index + 1 < input.Length && !char.IsUpper(input[index + 1])))) { result ??= []; result.Add(input[lower..index]); diff --git a/src/UnitTests/Bug/NamingConventions.cs b/src/UnitTests/Bug/NamingConventions.cs index 1344b0c8d..052402480 100644 --- a/src/UnitTests/Bug/NamingConventions.cs +++ b/src/UnitTests/Bug/NamingConventions.cs @@ -105,6 +105,24 @@ public void Should_map_from_pascal_to_lower() } } + +public class PascalCaseAcronymInPropertyName : AutoMapperSpecBase +{ + class Source { public Inner Form { get; set; } } + class Inner { public int XML { get; set; } } + class Dest { public int FormXML { get; set; } } + + protected override MapperConfiguration CreateConfiguration() => new(cfg => + cfg.CreateMap()); + + [Fact] + public void Should_flatten_acronym_property() + { + var result = Mapper.Map(new Source { Form = new Inner { XML = 42 } }); + result.FormXML.ShouldBe(42); + } +} + public class When_mapping_with_lowercase_naming_conventions_two_ways : AutoMapperSpecBase { private Dario _dario;