Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic collection mapping may break if interface mappings are added #89

Closed
jbogard opened this issue Sep 2, 2011 · 1 comment
Closed

Comments

@jbogard
Copy link
Member

jbogard commented Sep 2, 2011

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.

@jbogard jbogard closed this as completed in 4344a62 Nov 7, 2011
@lock
Copy link

lock bot commented May 8, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant