我有一种情况,我想使用较低的下划线映射到帕斯卡,但帕斯卡以另一种方式降低下划线。我的理解是配置文件可以做到这一点,但我正在努力让它发挥作用。这是我所拥有的:
Mapper.Initialize(cfg =>
{
cfg.AddProfile<FromUnderscoreMapping>();
cfg.AddProfile<ToUnderscoreMapping>();
});
Mapper.CreateMap<ArticleEntity, Article>().WithProfile("FromUnderscoreMapping");
...
public class FromUnderscoreMapping : Profile
{
protected override void Configure()
{
SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
DestinationMemberNamingConvention = new PascalCaseNamingConvention();
}
public override string ProfileName
{
get { return "FromUnderscoreMapping"; }
}
}
public class ToUnderscoreMapping : Profile
{
protected override void Configure()
{
SourceMemberNamingConvention = new PascalCaseNamingConvention();
DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
}
public override string ProfileName
{
get { return "ToUnderscoreMapping"; }
}
}