You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
atahualpa[CodePlex] Here's a small example case where polymorph mapping works and fails: interface IBase { } interface IDerived : IBase { } class Base : IBase { } class Derived : Base, IDerived { } class BaseDto { } class DerivedDto : BaseDto { }
and following mappings: Mapper.CreateMap<Base, BaseDto>().Include<Derived, DerivedDto>(); Mapper.CreateMap<Derived, DerivedDto>(); // try with and without the following two lines, also try with just the following two lines Mapper.CreateMap<IBase, BaseDto>().Include<IDerived, DerivedDto>(); Mapper.CreateMap<IDerived, DerivedDto>();
List<Base> list = new List<Base>() { new Derived() }; Console.WriteLine(Mapper.Map<IEnumerable<Base>, BaseDto[]>(list).First().GetType() == typeof(DerivedDto));
If the interface mappings are not created, the Console will output True as expected and documented. However if only the interface mappings are created it will output False. I had hoped that it would have worked with just the interfaces (even though I understand that this may be difficult with multiple interface inheritance), but I didn't expect that it doesn't work anymore when interface mappings were created in addition to the class mappings.
The text was updated successfully, but these errors were encountered:
atahualpa[CodePlex]
Here's a small example case where polymorph mapping works and fails:
interface IBase { }
interface IDerived : IBase { }
class Base : IBase { }
class Derived : Base, IDerived { }
class BaseDto { }
class DerivedDto : BaseDto { }
and following mappings:
Mapper.CreateMap<Base, BaseDto>().Include<Derived, DerivedDto>();
Mapper.CreateMap<Derived, DerivedDto>();
// try with and without the following two lines, also try with just the following two lines
Mapper.CreateMap<IBase, BaseDto>().Include<IDerived, DerivedDto>();
Mapper.CreateMap<IDerived, DerivedDto>();
List<Base> list = new List<Base>() { new Derived() };
Console.WriteLine(Mapper.Map<IEnumerable<Base>, BaseDto[]>(list).First().GetType() == typeof(DerivedDto));
If the interface mappings are not created, the Console will output True as expected and documented. However if only the interface mappings are created it will output False. I had hoped that it would have worked with just the interfaces (even though I understand that this may be difficult with multiple interface inheritance), but I didn't expect that it doesn't work anymore when interface mappings were created in addition to the class mappings.
The text was updated successfully, but these errors were encountered: