如何将AutoMapper配置为区分大小写?

时间:2016-10-29 08:20:54

标签: c# automapper

我希望以下测试失败,但事实并非如此。如何将AutoMapper配置为区分大小写?

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; }
    }
}

我正在使用AutoMapper的5.1.1版。

1 个答案:

答案 0 :(得分:0)

查看命名约定配置:https://github.com/AutoMapper/AutoMapper/wiki/Configuration#naming-conventions

在Profile或Mapper级别,您可以指定源和目标命名约定:

 var iframe = document.getElementsByTagName('iframe')[0];
     iframe.style.resize = 'vertical';

或者:

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