2015-06-05 96 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