For my objects, I use Csla, which has the BrokenRulesCollection property. I would like to convert this to my own DTO, which has the StatusMessages property.
I created my own resolver:
public class BrokenRulesCollectionResolver : ValueResolver<Csla.Validation.BrokenRulesCollection, StatusMessageList> { protected override StatusMessageList ResolveCore(Csla.Validation.BrokenRulesCollection source) { var messageList = new StatusMessageList(); messageList.ReadBrokenRules(source); return messageList; } }
And in the comparison, I make it clear which resolver to use:
Mapper.CreateMap<DomainObjects.Members.IMemberRegistration, DTO.Members.MemberRegistrationForm>() .ForMember(src => src.StatusMessages, opt => opt.ResolveUsing <BrokenRulesCollectionResolver>());
However, when I try to do a mapping:
return Mapper.Map<DomainObjects.Members.IMemberRegistration, DTO.Members.MemberRegistrationForm>(memberRegistration);
I get the following error:
The given value is of type Csla.Validation.BrokenRulesCollection, but Favs .DomainObjects.Members.MemberRegistration is expected. Change the source type of the value resolver or redirect the original value supplied to the value converter using FromMember.
Any suggestions?
Edit:
As a continuation, I also tried to create a converter, but I still get the same message:
public class BrokenRulesCollectionConverter : ITypeConverter<Csla.Validation.BrokenRulesCollection, StatusMessageList> { public StatusMessageList Convert(ResolutionContext context) { var test = new StatusMessageList(); test.ReadBrokenRules((Csla.Validation.BrokenRulesCollection)context.SourceValue); return test; } }
And configure it as follows:
Mapper.CreateMap<Csla.Validation.BrokenRulesCollection, StatusMessageList>() .ConvertUsing<BrokenRulesCollectionConverter>();