2015-06-05 95 views
3

我努力弄清楚如何映射基於來自Dictionary對象的鍵值。C#自動映射器映射字典屬性

這是我到目前爲止有:

.ForMember(dest => dest.Submitter, 
      opts => opts.MapFrom(src => src.opened_by)) 

注:src.open_by是一個字典對象。我想通過鍵進行搜索以獲取值映射到dest.Submitter

附加信息:

這裏是目標對象:

public class Incident 
{ 
    public int Active { get; set; } 
    public string Submitter { get; set; } 
} 

這裏是源對象:

Dictionary<string, string> opened_by = new Dictionary<string, string> 
{ 
    { "link", "https://someurl/674bd1f96f03e10071c35e02be3ee4ae" }, 
    { "value", "674bd1f96f03e10071c35e02be3ee4ae" } 
}; 

我的目標是從「值」鍵中獲取值674bd1f96f03e10071c35e02be3ee4ae以水合事件對象的「提交者」屬性

謝謝! :)

+1

什麼樣的字典對象的?關鍵和價值是什麼?源和目標類型是什麼樣的? –

+0

對不起,我只是增加了一些信息。 – jaypman

+0

不用擔心,謝謝更新 –

回答

3

你應該能夠得到映射器設置從字典這樣的特定值:

.ForMember(dest => dest.Submitter, 
     opts => opts.MapFrom(src => src.opened_by["value"])) 
+0

感謝您的快速回復:) – jaypman