using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Utils { public class EnumsMapper where T : Enum where U : Enum { readonly HashSet> mapper = new HashSet>(); public T GetModel(U entity) { var result = mapper.Where(tuple => tuple.Item2.Equals(entity)); if (result.Count() != 1) { return default(T); } return result.First().Item1; } public U GetEntity(T model) { var result = mapper.Where(tuple => tuple.Item1.Equals(model)); if (result.Count() != 1) { return default(U); } return result.First().Item2; } public void Add(T model, U entity) { mapper.Add(Tuple.Create(model, entity)); } public void AddRange(params Tuple[] tuples) { foreach (var t in tuples) { Add(t.Item1, t.Item2); } } public EnumsMapper(params Tuple[] tuples) { AddRange(tuples); } } }