2017-01-08 3 views
1

私は次の構造を持っている:私は先にソースコールAddString(メンバー)の各メンバーのためにそれをマッピングしたい交差Automapper収集処理

public class Destination 
{ 
    public Destination() 
    { 
     _StringCollection = new List<String>(); 
    } 
    private ICollection<String> _StringCollection; 
    public IEnumerable<String> StringCollection 
    { 
    get 
    { 
     return _StringCollection.AsEnumerable<String>(); 
    } 
    } 

    public void AddString(string str) 
    { 
     _StringCollection.Add(str); 
    } 
} 

public class Source 
{ 
    public List<String> StringCollection { get; set; } 
} 

を。

私はおそらく私はカスタムリゾルバで何かできると思っていたのですが、どう考えているようです。

答えて

1

あなたがソース内の各文字列のAddStringを実行するためにAfterMapを使用することができます。

Mapper.Initialize(cfg => 
    cfg.CreateMap<Source, Destination>() 
     .AfterMap((src,dest) => { 
      foreach (var s in src.StringCollection) 
       dest.AddString(s); 
     }));