Created
June 7, 2020 11:45
-
-
Save jasenf/e8b340632d2acb40b4b9874a544f2322 to your computer and use it in GitHub Desktop.
Enum Subsets
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
using System; | |
using AutoMapper; | |
public enum Roles | |
{ | |
Anonymous, | |
Employee, | |
Manager, | |
Admin, | |
Super | |
} | |
public enum PublicRoles | |
{ | |
Employee = Roles.Employee, | |
Manager = Roles.Manager, | |
Admin = Roles.Admin | |
} | |
public class Person | |
{ | |
public Roles Role { get; set; } | |
public string Email { get; set; } | |
} | |
public class CreatePersonDto | |
{ | |
public PublicRoles Role { get; set; } | |
public string Email { get; set; } | |
} | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var config = new MapperConfiguration(cfg => { | |
cfg.CreateMap<CreatePersonDto, Person>(); | |
}); | |
IMapper mapper = config.CreateMapper(); | |
var personToCreate = new CreatePersonDto { | |
Email = "[email protected]", | |
Role = PublicRoles.Admin | |
}; | |
var createdPerson = mapper.Map<Person>(personToCreate); | |
Console.WriteLine("Created person: e-mail={0}, role={1}", createdPerson.Email, createdPerson.Role); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment