繁体   English   中英

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

[英]How to configure AutoMapper to be case sensitive?

我希望以下测试失败,但不会失败。 如何将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; }
    }
}

我正在使用5.1.1版的AutoMapper

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

在概要文件或映射器级别,您可以指定源和目标命名约定:

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

要么:

public class OrganizationProfile : Profile 
{
  public OrganizationProfile() 
  {
    SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
    DestinationMemberNamingConvention = new PascalCaseNamingConvention();
    //Put your CreateMap... Etc.. here
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM