linq - Correct implementation of IGrouping to be used inside longlistselector groupheader -


i have observablecollection following-

    private observablecollection<keyedlist<int, anime>> _grp;     public observablecollection<keyedlist<int, anime>> groupedanimebygenre     {                 {             return _grp;          }         set         {             _grp = value;             raisepropertychanged("groupedanimebygenre");         }     } 

i using populate longlistselector grouping. keyedlist implemented this-

public class keyedlist<tkey, titem> : list<titem> {     public tkey key { protected set; get; }      public keyedlist(tkey key, ienumerable<titem> items)         : base(items)     {         key = key;     }      public keyedlist(igrouping<tkey, titem> grouping)         : base(grouping)     {         key = grouping.key;     } } 

i have following code feed observablecollection. keep in mind animelist2 temporary collection.

 var groupfinale = animelist2.groupby(txt => txt.id).where(grouping => grouping.count() > 1).toobservablecollection();   groupedanimebygenre = groupfinale ; 

but unable convert/use groupfinale groupedanimebygenre. missing extension method part not aware of syntax. please help

if remove toobservablecollection() call , take part

var groupfinale = animelist2.groupby(txt => txt.id).where(grouping => grouping.count() > 1); 

you'll see type of groupfinale ienumerable<igrouping<int, anime>>. hence applying toobservablecollection() result in observablecollection<igrouping<int, anime>>. however, type of groupedanimebygenre observablecollection<keyedlist<int, anime>>. need convert ienumerable<igrouping<int, anime>> ienumerable<keyedlist<int, anime>> in linq performed select method.

shortly, can use

var groupfinale = animelist2     .groupby(txt => txt.id)     .where(grouping => grouping.count() > 1)     .select(grouping => new keyedlist<int, anime>(grouping))     .toobservablecollection(); 

you can make such conversion easier providing extension method (similar bcl provided toarray() / tolist()) allow skipping type arguments

public static class keyedlist {     public static keyedlist<tkey, titem> tokeyedlist<tkey, titem>(this igrouping<tkey, titem> source)     {         return new keyedlist<tkey, titem>(source);      } } 

then can use

var groupfinale = animelist2     .groupby(txt => txt.id)     .where(grouping => grouping.count() > 1)     .select(grouping => grouping.tokeyedlist())     .toobservablecollection(); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -