The TypeAdapterSetter.Include method as demonstrated here to adapt derived types only works when the TypeAdapter.Adapt method is provided both TSource and TDestination type parameters.
When the method TypeAdapter.Adapt is provided both TSource and TDestination type parameters, the behavior is as expected:
Vehicule car = new Car() { Make = "Toyota" };
VehiculeDto actual = car.Adapt<Vehicule, VehiculeDto>();
Assert.True(actual is CarDto);
However, when the method TypeAdapter.Adapt is only provided the TDestination type parameter, the derived type is not adapted:
Vehicule car = new Car() { Make = "Toyota" };
VehiculeDto actual = car.Adapt<VehiculeDto>();
Assert.True(actual is CarDto); // Assert.True() Failure, Expected: True, Actual: False
Hello, I think, these are different types of adapters.
car.Adapt<VehiculeDto>(); This is a directive adapter. you have to get exactly what was requested - VehiculeDto
Hello,
The
TypeAdapterSetter.Include
method as demonstrated here to adapt derived types only works when theTypeAdapter.Adapt
method is provided bothTSource
andTDestination
type parameters.Given this configuration:
When the method
TypeAdapter.Adapt
is provided bothTSource
andTDestination
type parameters, the behavior is as expected:However, when the method
TypeAdapter.Adapt
is only provided theTDestination
type parameter, the derived type is not adapted:Is there any way to fix this?
Thanks