These are my classes:
public class EventLog {
public string SystemId { get; set; }
public string UserId { get; set; }
public List<
You will need these three mapings with one custom converter:
Mapper.CreateMap(); // maps message and event id
Mapper.CreateMap(); // maps system id and user id
Mapper.CreateMap>()
.ConvertUsing(); // creates collection of dto
Thus you configured mappings from Event
to EventDTO
and from EventLog
to EventDTO
you can use both of them in custom converter:
class EventLogConverter : ITypeConverter>
{
public IEnumerable Convert(ResolutionContext context)
{
EventLog log = (EventLog)context.SourceValue;
foreach (var dto in log.Events.Select(e => Mapper.Map(e)))
{
Mapper.Map(log, dto); // map system id and user id
yield return dto;
}
}
}
Sample code with NBuilder:
var log = new EventLog {
SystemId = "Skynet",
UserId = "Lazy",
Events = Builder.CreateListOfSize(5).Build().ToList()
};
var events = Mapper.Map>(log);