Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping to a custom type which has an internal constructor

We are trying to map an object - a Tridion Outbound Email Contact - which has a custom dictionary type property with an internal constructor - ExtendedDetailCollection

It's fine mapping from the object onto a Viewmodel

Mapper.CreateMap<Contact,ContactViewModel>()
    .ForMember(x=>x.Name, m=>m.MapFrom(x=>x.ExtendedDetails["Name"].StringValue))

but the other way does not work

We have tried:

Mapper.CreateMap<ContactViewModel,Contact>()
    .ForMember(x=>x.ExtendedDetails["Name"].Value, m => m.MapFrom(x=>x.Name));

but that throws a runtime exception.

Edit: The message of the exception is:

AutoMapper.AutoMapperConfigurationException : Custom configuration for members is only supported for top-level individual members on a type.

We have also tried the various type converters and value resolvers but none allow us to get at the object being mapped to, which is what we need to get access to in order to map the ExtendedDetails object.

Mapper.CreateMap<ContactViewModel,Contact>()
    .ForMember(x=>x.ExtendedDetails, m => ????);

Is there a pattern for this or is it easier just to use a static method?

like image 231
Rob Stevenson-Leggett Avatar asked Nov 13 '22 08:11

Rob Stevenson-Leggett


1 Answers

If ExtendedDetails is a class you need to createMap for this class and then individual property like Name of the class.

like image 83
Ram Avatar answered Nov 16 '22 03:11

Ram