65.9K
CodeProject is changing. Read more.
Home

Select Recursive Extension method

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Sep 7, 2010

CPOL
viewsIcon

7790

Magnus, I really like the idea! I believe your original idea (posted @ http://www.codeproject.com/KB/linq/LinqToTree.aspx) is even better for the general case - probably better than the solution in the article - it does feel more generic while still being very easy to use.I'm sure you may...

Magnus, I really like the idea! I believe your original idea (posted @ http://www.codeproject.com/KB/linq/LinqToTree.aspx) is even better for the general case - probably better than the solution in the article - it does feel more generic while still being very easy to use. I'm sure you may have already implemented something like this, but if you precede SelectRecursive() with the following, you can begin the operation with a single item.
public static IEnumerable<T> YieldSame<T>(this T item)
{
    yield return item;
}

// Example
Window w = new Window();
w.YieldSame().SelectRecursive(w => w.OwnedWindows);
Again, excellent idea!