Last active
December 31, 2017 15:11
-
-
Save anytizer/029a9c6c982340507e8bc523784cac47 to your computer and use it in GitHub Desktop.
Auto Mapper
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
Mapper.Initialize(cfg => { | |
cfg.CreateMap<account_roles, RoleDTO>() | |
.ForMember(x => x.id, opt => opt.MapFrom(x => x.role_id)) | |
.ForMember(x => x.name, opt => opt.MapFrom(x => x.role_name)) | |
; | |
cfg.CreateMap<account_users, UserDTO>() | |
.ForMember(x => x.id, opt => opt.MapFrom(x => x.user_id)) | |
.ForMember(x => x.email, opt => opt.MapFrom(x => x.user_email)) | |
; | |
}); | |
public RoleDTO[] roles() | |
{ | |
account_roles[] roles = ae.account_roles.ToArray(); | |
RoleDTO[] r = new RoleDTO[roles.Length]; | |
for(int i=0; i<roles.Length; ++i) | |
{ | |
r[i] = Mapper.Map<account_roles, RoleDTO>(roles[i]); | |
} | |
return r; | |
} | |
public UserDTO[] users() | |
{ | |
account_users[] users = ae.account_users.ToArray(); | |
UserDTO[] r = new UserDTO[users.Length]; | |
for (int i = 0; i < users.Length; ++i) | |
{ | |
r[i] = Mapper.Map<account_users, UserDTO>(users[i]); | |
} | |
return r; | |
} | |
// array | |
UserDTO[] r = Mapper.Map<account_users[], UserDTO[]>(users); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Details here.