[英]C# Automapper Mapping Dictionary Property
I'm struggling to figure out how to map a value based on key from Dictionary object. 我正在努力弄清楚如何根据Dictionary对象的键来映射值。
Here is what I have so far: 这是我到目前为止:
.ForMember(dest => dest.Submitter,
opts => opts.MapFrom(src => src.opened_by))
Note: src.open_by is a dictionary object. 注意:src.open_by是一个字典对象。 I would like to search by key to get value to map to dest.Submitter
我想按键搜索以获取映射到dest.Submitter的值
Additional info: 附加信息:
Here is the destination object: 这是目标对象:
public class Incident
{
public int Active { get; set; }
public string Submitter { get; set; }
}
Here is the source object: 这是源对象:
Dictionary<string, string> opened_by = new Dictionary<string, string>
{
{ "link", "https://someurl/674bd1f96f03e10071c35e02be3ee4ae" },
{ "value", "674bd1f96f03e10071c35e02be3ee4ae" }
};
My goal is to get the the value 674bd1f96f03e10071c35e02be3ee4ae from the "value" key to hydrate the "Submitter" property of the Incident object 我的目标是从“value”键获取值674bd1f96f03e10071c35e02be3ee4ae以水合Incident对象的“Submitter”属性
Thanks! 谢谢! :)
:)
You should be able to get the mapper to set the specific value from the Dictionary like this: 您应该能够让映射器从Dictionary中设置特定值,如下所示:
.ForMember(dest => dest.Submitter,
opts => opts.MapFrom(src => src.opened_by["value"]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.