2016-04-19 5 views
0

私は、パスカルケース名を持つクラスから、後置名と接頭辞を付けたアンダースコアのクラスへのマッピングを処理するマッピング規約を登録しようとしています。私は例に従おうとしましたが、どのように動作するかについて頭を下げることはできません。AutoMapperプロパティ名の変換

これは、それが(:)私の意見では)動作するはずのように見えること、私が試した多くのものの一つですが、何もしていないようだ。

​​

私は何ここに行方不明?

答えて

0

最終的には解決策が見つかりました。私は2つのプロファイルを作成しました。各プロファイルはそれぞれの「方向」に対応しており、マッピングが追加されています。

同じファイル(ビジネスエリアでグループ化する)にマッピングするのではなく、あまりにも満足していません。しかし、少なくともそれは動作します... :)

私はまた、同じプロファイルに登録を入れて、.WithProfile( "ToUnderscoreWithPrefix")メソッドを使ってみましたが、動作させることができませんでした。

Mapper.Initialize(cfg => 
{ 
    cfg.AddProfile(new ToUnderscoreWithPrefixMappings()); 
    cfg.AddProfile(new FromUnderscoreWithPrefixMappings()); 
}); 

public class ToUnderscoreWithPrefixMappings : Profile 
{ 
    protected override void Configure() 
    { 
     RecognizeDestinationPrefixes("P", "p"); 

     SourceMemberNamingConvention = new PascalCaseNamingConvention(); 
     DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention(); 

     CreateMap<PascalCaseEntity, UnderscoreWithPrefixAndPostfixEntity>(); 
    } 

    public override string ProfileName { get; } = "ToUnderscoreWithPrefix"; 
} 

public class FromUnderscoreWithPrefixMappings : Profile 
{ 
    protected override void Configure() 
    { 
     RecognizePrefixes("P_", "p_"); 
     RecognizePostfixes("_"); 

     SourceMemberNamingConvention = new LowerUnderscoreNamingConvention(); 
     DestinationMemberNamingConvention = new PascalCaseNamingConvention(); 

     CreateMap<UnderscoreWithPrefixAndPostfixEntity, PascalCaseEntity>(); 
    } 

    public override string ProfileName { get; } = "FromUnderscoreWithPrefix"; 
} 
関連する問題