Access MemberName/PropertyMap from ResolutionContext in an Automapper custom ValueResolver -


i need trace complex (i.e. non-default) mappings in our project.

to achieve this, i'm using custom value resolver, , publishing out log event during resolution. part of message i'd know destination member being mapped, hoping find in source.context.membername - null.

valueresolver:

public class resolver : ivalueresolver {      public event mappingeventhandler mappingevent;     public delegate void mappingeventhandler(mappingmessage m);      public resolutionresult resolve(resolutionresult source)     {         var src = (sourcedto)source.context.sourcevalue;          if (!string.isnullorwhitespace(src.status) && src.status == "alert")         {             var newvalue = source.value + " - fail";             var fieldname = source.context.membername; //always null              mappingevent(new mappingmessage(fieldname , newvalue));              return source.new(value, typeof(string));         }          return source;     } } 

... , usage:

resolver resolver = new resolver();  //... subscribe resolver events etc.  mapper.createmap<sourcedto, common>()       .formember(dest => dest.referenceidentifier                 , opt => opt.resolveusing<resolver>()                             .frommember(src => src.reference)                             .constructedby(() => resolver) 

i can see in automapper code membername returns if propertymap non-null, , since propertymap null in case, i'm not getting membername back.

is there reason propertymap isn't being defined in here? there's relevant candidate via source.context.typemap.getpropertymaps(), it's not being pushed context.

any ideas? perhaps there's means of pulling right propertymap out of context.typemap set?

tried more recent automapper build - looks problem has been resolved.

version issue: 2.1.266

working version: 2.2.1

also found it's lot easier use following syntax resolve existing instance:

resolver resolver = new resolver();  //... subscribe resolver events etc.  mapper.createmap<sourcedto, common>()                       .formember(dest => dest.referenceidentifier                                 , opt => opt.resolveusing(resolver)                                             .frommember(src => src.reference) ) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -