1

This is a reach, but I am going to ask anyway.

I'll lead with my example:

public class PatientInfoModel : IPatientInfoModel, IHaveCustomMappings
{
    public string PatientId { get; set; }
    public string PatientIdForView { get; set; }
    public PatientEpisodeData PatientEpisode { get; set; }

    public void CreateMappings(Profile configuration)
    {
        configuration.CreateMap<PatientInfoRawDto, PatientInfoModel>()
            .ForMember(m => m.PatientIdForView, opt => opt.ResolveUsing<PatientIdResolver<PatientInfoRawDto, PatientInfoModel>>())
            .ForMember(m => m.PatientId, opt => opt.MapFrom(p => p.patID))
            .ForMember(m => m.PatientEpisode, opt => opt.MapFrom(p => new PatientEpisodeData
            {
                PatientId = p.patID,
                PatientIdForView = this.PatientIdForView
            }));
    }

    public class PatientEpisodeData
    {
        public int PatientId { get; set; }
        public string PatientIdForView { get; set; }
    }
}

As you can see, with the member PatientEpisode, I would like to map from one of the properties which has already been resolved (PatientIdForView).

As I could not figure out how to do this, I just set the property after the fact. But it would be interesting to find out if this is possible.

Note: I'm not really interested in using a custom value resolver unless you could pass the PatientIdForView property to it.

Cheers

2
  • I think this is what they have .AfterMap((src, dest) => dest.Name = "John"); for but I could be misunderstanding you're question. Commented Aug 15, 2016 at 17:28
  • @MisterIsaak Thanks. I did try AfterMap, but it does not work. The PatientIdForView property is null. Commented Aug 16, 2016 at 0:21

1 Answer 1

2

Custom value resolvers do allow you to pass in the destination member value into it (I assume that's what the PatientIdForView property you mention is, the destination member value). If you need the source member value, you can use a member value resolver:

http://docs.automapper.org/en/stable/Custom-value-resolvers.html

You get the destination member, the source member that you specify, and the source/destination objects. Should be everything you need!

Sign up to request clarification or add additional context in comments.

1 Comment

that worked. I missed that interface when i read the documentation. Tremendous!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.