C # Automapper Dictionary Properties Mapping

I am trying to figure out how to match a value based on a key from a dictionary.

Here's what I have so far:

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

      

Note: src.open_by is a dictionary object. I would like to search by key to get the value to map to dest.Submitter

Additional Information:

Here is the target:

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

      

Here's the original object:

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

      

My goal is to get the value 674bd1f96f03e10071c35e02be3ee4ae from the key "value" to moisten the "Sender" property of the "Incident" object

Thank!:)

+3


source to share


1 answer


You should be able to force mapper to set a specific value from the Dictionary like this:



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

      

+3


source







All Articles