パスカルに下線を使用して一方向にマップしたい状況がありますが、パスカルを下線に別の方法でマップしたい場合があります。私の理解では、プロファイルがこれを行うことができますが、それを機能させるのに苦労しています. ここに私が持っているものがあります:
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"; }
}
}