For my objects, I am using Csla, which has a BrokenRulesCollection property. I would like to convert that to my own DTO which has 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 mapping, I'm letting it know 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 the mapping:
return Mapper.Map<DomainObjects.Members.IMemberRegistration, DTO.Members.MemberRegistrationForm>(memberRegistration);
I get the following error:
Value supplied is of type Csla.Validation.BrokenRulesCollection but expected Favs.DomainObjects.Members.MemberRegistration. Change the value resolver source type, or redirect the source value supplied to the value resolver using FromMember.
Any suggestions?
Edit:
As a follow up, I have also tried to create a convert but 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>();