Created
January 30, 2018 10:11
-
-
Save lbargaoanu/31d8236589f29f2e530ada5dbeccdaf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void Main(string[] args) | |
| { | |
| Mapper.Initialize(cfg => | |
| { | |
| cfg.CreateMap<IBaseUserDto, IBaseUserEntity>() | |
| .ForMember(d=>d.Name, opt => opt.Ignore()); | |
| cfg.CreateMap(typeof(BaseUserDto<>), typeof(BaseUserEntity<>)); | |
| cfg.CreateMap(typeof(ConcreteUserDto), typeof(ConcreteUserEntity)) | |
| .IncludeBase(typeof(IBaseUserDto), typeof(IBaseUserEntity)); | |
| }); | |
| var user = new ConcreteUserDto | |
| { | |
| Id = "my-id", | |
| Name = "my-User" | |
| }; | |
| var userEntity = Mapper.Map<ConcreteUserEntity>(user).Dump(); | |
| } | |
| public interface IBaseUserDto | |
| { | |
| string Name { get; set; } | |
| } | |
| public abstract class BaseUserDto<TIdType> : IBaseUserDto | |
| { | |
| public TIdType Id { get; set; } | |
| public string Name { get; set; } | |
| } | |
| public class ConcreteUserDto : BaseUserDto<string> | |
| { | |
| } | |
| public interface IBaseUserEntity | |
| { | |
| string Name { get; set; } | |
| } | |
| public abstract class BaseUserEntity<TIdType> : IBaseUserEntity | |
| { | |
| public TIdType Id { get; set; } | |
| public string Name { get; set; } | |
| } | |
| public class ConcreteUserEntity : BaseUserEntity<string> | |
| { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment