Skip to content

Instantly share code, notes, and snippets.

@jasenf
Created June 7, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasenf/e8b340632d2acb40b4b9874a544f2322 to your computer and use it in GitHub Desktop.
Save jasenf/e8b340632d2acb40b4b9874a544f2322 to your computer and use it in GitHub Desktop.
Enum Subsets
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 = "whoami@youneedtoask.com",
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