5

I expect the following test to fail, but it doesn't. How can I configure AutoMapper to be case sensitive?

public class AutomapperTests
{
    [Fact]
    public void CaseSensitiveTest()
    {
        Mapper.Initialize(cfg => cfg.AddMemberConfiguration().AddName<CaseSensitiveName>());

        Mapper.Initialize(cfg => cfg.CreateMap<Source, Destination>());

        Mapper.AssertConfigurationIsValid();
    }

    public class Source
    {
        public int Foo { get; set; }
    }

    public class Destination
    {
        public int FoO { get; set; }
    }
}

I'm using version 5.1.1 of AutoMapper.

david.s
  • 11,283
  • 6
  • 50
  • 82
  • Possible duplicate of [Automapper - want case sensitive](http://stackoverflow.com/questions/20600081/automapper-want-case-sensitive) – Operatorius Oct 29 '16 at 10:20
  • @Operatorius I've already seen the other question before posting mine and the problem is that it has no real answer. Just 2 links to things that do not apply (or no longer apply) and a third dead link. – david.s Oct 29 '16 at 11:53

1 Answers1

1

Take a look at the naming convention configurations: https://github.com/AutoMapper/AutoMapper/wiki/Configuration#naming-conventions

At the Profile or Mapper level you can specify the source and destination naming conventions:

Mapper.Initialize(cfg => {
  cfg.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
  cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
});

Or:

public class OrganizationProfile : Profile 
{
  public OrganizationProfile() 
  {
    SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
    DestinationMemberNamingConvention = new PascalCaseNamingConvention();
    //Put your CreateMap... Etc.. here
  }
}
shenku
  • 11,969
  • 12
  • 64
  • 118