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

C# 如何将AutoMapper配置为区分大小写?,c#,automapper,C#,Automapper,我预计下面的测试会失败,但事实并非如此。如何将AutoMapper配置为区分大小写 public class AutomapperTests { [Fact] public void CaseSensitiveTest() { Mapper.Initialize(cfg => cfg.AddMemberConfiguration().AddName<CaseSensitiveName>()); Mapper.Initia

我预计下面的测试会失败,但事实并非如此。如何将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; }
    }
}
公共类测试
{
[事实]
公开无效案件敏感度测试()
{
初始化(cfg=>cfg.AddMemberConfiguration().AddName());
初始化(cfg=>cfg.CreateMap());
assertConfigurationsValid();
}
公共类源
{
公共int Foo{get;set;}
}
公务舱目的地
{
公共int FoO{get;set;}
}
}

我使用的是的5.1.1版。

看看命名约定配置:

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

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


@Operatorius的可能副本我在发布我的问题之前已经看到了另一个问题,问题是它没有真正的答案。只有两个指向不适用(或不再适用)的内容的链接和第三个死链接。
public class OrganizationProfile : Profile 
{
  public OrganizationProfile() 
  {
    SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
    DestinationMemberNamingConvention = new PascalCaseNamingConvention();
    //Put your CreateMap... Etc.. here
  }
}