I need to configure AutoMapper to Conditionaly map one target property to two different source properties:
public class JourneyDTO
{
public VehicleDTO vehicle { get; set; }
}
public class Journey
{
public Car car { get; set; }
public Bus bus { get; set; }
}
public class Car
{
}
public class Bus
{
}
and then AutoMapper configuration:
.ForMember(m => m.vehicle, src => {
src.PreCondition(p => (p.bus != null));
src.MapFrom(f => f.bus);
})
.ForMember(m => m.vehicle, src => {
src.PreCondition(p => (p.car!= null));
src.MapFrom(f => f.car);
})
On my result JourneyDTO I only get vehicle filled with car
. If there is no car
, only bus
on source object, then DTO vehicle
property is null
Any hint?
Thanks!