Open generic map configs with IncludeAllDerived #4037
-
I've got a very contrived, hopefully simplified, example of my project: public interface ITrackEntityCreated
{
DateTimeOffset Created { get; set; }
}
public interface ITrackEntityUpdated
{
DateTimeOffset? Updated { get; set; }
}
public class User: ITrackEntityCreated, ITrackEntityUpdated
{
public DateTimeOffset Created { get; set; }
public DateTimeOffset? Updated { get; set; }
} both public class TrackEntityMaps: Profile
{
public TrackEntityMaps()
{
CreateMap<object, ITrackEntityCreated>()
.IncludeAllDerived()
.ForMember(dest => dest.Created, opts => opts.Ignore());
CreateMap<object, ITrackEntityUpdated>()
.IncludeAllDerived()
.ForMember(dest => dest.Updated, opts => opts.Ignore());
}
} I've found some behavior I don't understand with the following configuration. I was expecting my open generic map configuration to inherit the configuration above because both my source and destination derive from public class UserCommandMaps : Profile
{
public UserCommandMaps()
{
// this works. it inherits the mapping configs defined in TrackEntityMaps
CreateMap<UpdateUserCommand<Model.V1.User>, User>();
CreateMap<UpdateUserCommand<Model.V2.User>, User>();
// this doesn't inherit
CreateMap(typeof(UpdateUserCommand<>), typeof(User));
// this does "inherit" explicitly
CreateMap(typeof(UpdateUserCommand<>), typeof(User))
.IncludeBase(typeof(object), typeof(ITrackEntityCreated))
.IncludeBase(typeof(object), typeof(ITrackEntityUpdated));
}
} Is this expected behavior or does this surprise anyone? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I guess it should work. A PR is welcome. You can target my branch as it's way ahead of master. I, for one, prefer the explicit version :) |
Beta Was this translation helpful? Give feedback.
-
It seems you're using an older version. Try the MyGet build and go downward. |
Beta Was this translation helpful? Give feedback.
It seems you're using an older version. Try the MyGet build and go downward.