C# Automapper 映射字典属性

jay*_*man 4 c# dictionary

我正在努力弄清楚如何根据 Dictionary 对象中的键映射值。

这是我到目前为止所拥有的:

.ForMember(dest => dest.Submitter,
            opts => opts.MapFrom(src => src.opened_by))
Run Code Online (Sandbox Code Playgroud)

注意:src.open_by 是一个字典对象。我想按键搜索以获取映射到 dest.Submitter 的值

附加信息:

这是目标对象:

public class Incident
{
    public int Active { get; set; }
    public string Submitter { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是源对象:

Dictionary<string, string> opened_by = new Dictionary<string, string>
{
    { "link", "https://someurl/674bd1f96f03e10071c35e02be3ee4ae" },
    { "value", "674bd1f96f03e10071c35e02be3ee4ae" }
};
Run Code Online (Sandbox Code Playgroud)

我的目标是从“value”键获取值 674bd1f96f03e10071c35e02be3ee4ae 以水合事件对象的“Submitter”属性

谢谢!:)

Mar*_*rry 5

您应该能够让映射器从字典中设置特定值,如下所示:

.ForMember(dest => dest.Submitter,
        opts => opts.MapFrom(src => src.opened_by["value"]))
Run Code Online (Sandbox Code Playgroud)