public SimpleItem[] Simplify() { return(Items.OrderBy(x => x.Name) .ThenBy(x => x.Position) .GroupBy(x => x.Name, x => x, (name, group) => SimpleItem.CreateInstance(name, group)) .ToArray() ); }
public static SimpleItem CreateInstance(string name, IEnumerable <Item> items) { List <int> values = new List <int>(); int i = 0; foreach (Item item in items.OrderBy(x => x.Position)) { if (item.Position != i++) { throw new InvalidOperationException("bad data"); } values.Add(item.Value); } SimpleItem instance = new SimpleItem(name, values.ToArray()); return(instance); }