Say I have a \'Comment\' property on a \'Message\' class. I also have 2 class properties which have a \'Body\' property. If the class has either of the class properties se
Use a ValueResolver:
.ForMember(dto => dto.Comment, opt => opt.ResolveUsing<CommentResolver>().FromMember(src => src))
And then the actual implementation:
public class CommentResolver: ValueResolver<Message, string>
{
protected override string ResolveCore(Message msg)
{
//logic goes here
if (msg.InboundMessage != null)
return msg.InboundMessage.Body;
else if (msg.OutboundMessage != null)
return msg.OutboundMessage.Body;
else
return msg.Comment;
}
}