Exemple #1
0
 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()
            );
 }
Exemple #2
0
        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);
        }