Exemplo n.º 1
0
        public static KeyedList GetOrAddGroup(this GroupedList list, string key)
        {
            // get group (keyed list) in grouped list with specified key
            // if no group is found, new group is created and returned

            if (list.Any(g => g.Key == key))
            {
                return(list.First(g => g.Key == key));
            }
            else
            {
                var newGroup = new KeyedList(key);
                list.Add(newGroup);
                return(newGroup);
            }
        }
Exemplo n.º 2
0
        public static GroupedList GetGroupedList(this IEnumerable <IHasCategory> list)
        {
            var query = from item in list
                        group item by item.Category into g
                        orderby g.Key
                        select new { GroupName = g.Key, Items = g };

            var groups = new ObservableCollection <KeyedList>();

            foreach (var g in query)
            {
                KeyedList info = new KeyedList(g.GroupName);
                foreach (var item in g.Items)
                {
                    info.Add(item);
                }
                groups.Add(info);
            }

            return(groups);
        }