c# - AutoMapping objects -


i have weird situation have objects , lists of objects part of entities , contracts interface third-party service. i'm going try see if can replace actual object class more specific in entities , contracts around this, curious if there way automapper handle is.

here dummy classes:

public class {     public object item { get; set; } }  public class fromobject {     public string value { get; set; } }  public class {     public object item { get; set; } }  public class toobject {     public string value { get; set; } } 

and quick replication:

mapper.createmap<from, to>(); mapper.createmap<fromobject, toobject>();  from = new { item = new fromobject { value = "test" } }; to = mapper.map<to>(from); string type = to.item.gettype().name; // fromobject 

basically, question this: there way automapper understand from.item fromobject , apply mapping toobject? i'm thinking there's not way make automatic, since there's nothing indicate to.item has toobject, there way specify during createmap or map calls should taken account?

i don't think there "automatic" way of doing it, since automapper won't able figure out from.item fromobject , to.item toobject.

but, while creating mapping, can specify that

mapper.createmap<fromobject, toobject>(); mapper.createmap<from, to>()     .formember(dest => dest.item, opt => opt.mapfrom(src => mapper.map<toobject>(src.item)));              from = new { item = new fromobject { value = "test" } }; to = mapper.map<to>(from); string type = to.item.gettype().name; // toobject 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -