3

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

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

1 に答える 1

7

マッピングを構成に移動する必要があります。

public class FromUnderscoreMapping : Profile
{
    protected override void Configure()
    {
        SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
        DestinationMemberNamingConvention = new PascalCaseNamingConvention();
        CreateMap<ArticleEntity, Article>();
    }

    public override string ProfileName
    {
        get { return "FromUnderscoreMapping"; }
    }
}

public class ToUnderscoreMapping : Profile
{
    protected override void Configure()
    {
        SourceMemberNamingConvention = new PascalCaseNamingConvention();
        DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
        CreateMap<Article, ArticleEntity>();
    }

    public override string ProfileName
    {
        get { return "ToUnderscoreMapping"; }
    }
}
于 2013-09-19T18:07:38.523 に答える