using System; using System.Collections.Generic; using System.Linq; namespace Common { public class NamedList { public string Name; public List List; } public class NamedLists : List { public void Add(string name, string listItemName) { NamedList item = this.FirstOrDefault(x => x.Name == name); if (item == null) { item = new NamedList { Name = name, List = new List() }; Add(item); } if (!item.List.Contains(listItemName)) { item.List.Add(listItemName); } } public NamedLists GetReverse() { NamedLists result = new NamedLists(); foreach (NamedList item in this) { foreach (string item2 in item.List) { result.Add(item2, item.Name); } } return result; } } }