Wednesday, May 28, 2014

Linqing non liqable Collections

 

If you’re a linq lover like myself maybe you’ve come across gems like .

SelectedRows
ItemCollection
CheckedItems
 
if your collection offers you GetEnumerator then you’re set. use Linq’s less known helper function OfType<T>()
This great function utilizes the GetEnumerator and turns it into a one way casting of al objects as queryable objects.
From there, it’s a hop skip and jump to Linq.
such as:

Wb1.Document.Links.OfType<HtmlElement>()
                .ToList()
                .ForEach(x => x.Click+=x_Click  );