<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" 	>
<channel>
	<title>Comments on: Traverse a hierarchical structure with LINQ-to-Hierarchical</title>
	<atom:link href="http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/</link>
	<description>Arjan: Technical Learnings of Programmings for Make Benefit Glorious Framework of .NET</description>
	<lastBuildDate>Sat, 17 Dec 2011 08:36:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Jaime</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1244</link>
		<dc:creator>Jaime</dc:creator>
		<pubDate>Sat, 17 Dec 2011 08:36:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1244</guid>
		<description>This looks pretty good. I couldn&#039;t figure out how to work this out where the root element is not a hierarchical type. In my case a ProjectTemplate has a Folders collection and the Folder objects in the Folders collections also contain collections of folders.

Can someone improve upon my solution as I worked it out below to make it a little more elegate(ie remove the result list from the recursive function.

    public static class ProjectTemplateExtensions
    {
        public static IEnumerable RazorTemplates(this ProjectTemplate projectTemplate)
        {
            var razorTemplates = new List();
            foreach (var folder in projectTemplate.Folders)
            {
                PopulateRazorTemplates(folder, ref razorTemplates);
            }
        }


        public static void PopulateRazorTemplates(Folder folder, ref List razorTemplates)
        {
            razorTemplates.AddRange(folder.RazorTemplates);

            foreach (var childFolder in folder.Folders)
            {
                PopulateRazorTemplates( childFolder, ref razorTemplates);
            }
        }
    }</description>
		<content:encoded><![CDATA[<p>This looks pretty good. I couldn&#8217;t figure out how to work this out where the root element is not a hierarchical type. In my case a ProjectTemplate has a Folders collection and the Folder objects in the Folders collections also contain collections of folders.</p>
<p>Can someone improve upon my solution as I worked it out below to make it a little more elegate(ie remove the result list from the recursive function.</p>
<p>    public static class ProjectTemplateExtensions<br />
    {<br />
        public static IEnumerable RazorTemplates(this ProjectTemplate projectTemplate)<br />
        {<br />
            var razorTemplates = new List();<br />
            foreach (var folder in projectTemplate.Folders)<br />
            {<br />
                PopulateRazorTemplates(folder, ref razorTemplates);<br />
            }<br />
        }</p>
<p>        public static void PopulateRazorTemplates(Folder folder, ref List razorTemplates)<br />
        {<br />
            razorTemplates.AddRange(folder.RazorTemplates);</p>
<p>            foreach (var childFolder in folder.Folders)<br />
            {<br />
                PopulateRazorTemplates( childFolder, ref razorTemplates);<br />
            }<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aeinbu</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1240</link>
		<dc:creator>aeinbu</dc:creator>
		<pubDate>Thu, 20 Oct 2011 06:43:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1240</guid>
		<description>In &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.control.aspx&quot; rel=&quot;nofollow&quot;&gt;MSDN&lt;/a&gt; it says that the Control class exposes a Controls collection. The example in the last codeblock in the article should work!</description>
		<content:encoded><![CDATA[<p>In <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.aspx" rel="nofollow">MSDN</a> it says that the Control class exposes a Controls collection. The example in the last codeblock in the article should work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robson Rocha</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1239</link>
		<dc:creator>Robson Rocha</dc:creator>
		<pubDate>Thu, 20 Oct 2011 01:56:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1239</guid>
		<description>How can you use it with the Controls collection of the System.Web.UI.Control class?

It does not expose an sub-list, but the elements exposed by the Controls colection expose the Controls property.</description>
		<content:encoded><![CDATA[<p>How can you use it with the Controls collection of the System.Web.UI.Control class?</p>
<p>It does not expose an sub-list, but the elements exposed by the Controls colection expose the Controls property.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aeinbu</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1201</link>
		<dc:creator>aeinbu</dc:creator>
		<pubDate>Fri, 16 Sep 2011 22:48:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1201</guid>
		<description>Hi Gary!

I did your homework (in C#) ;) I made a new class LevelAndData, which is used both internally in the new &lt;code&gt;FlattenHierarchyWithLevels&lt;/code&gt; method and as the return type.

I think this does what you ask:

&lt;pre lang=&quot;csharp&quot;&gt;public static class LinqToHierarchical
{
	public class LevelAndData&lt;T&gt;
	{
		public int Level { get; set; }
		public T Data { get; set; }
	}

	public static IEnumerable&lt;LevelAndData&lt;T&gt;&gt; FlattenHierarchyWithLevel&lt;T&gt;(this T node, Func&lt;T, IEnumerable&lt;T&gt;&gt; getChildEnumerator)
	{
		yield return new LevelAndData&lt;T&gt; {Level = 1, Data = node};
		if (getChildEnumerator(node) != null)
		{
			foreach (var child in getChildEnumerator(node))
			{
				foreach (var childOrDescendant in child.FlattenHierarchyWithLevel(getChildEnumerator))
				{
					yield return new LevelAndData&lt;T&gt;{ Level = childOrDescendant.Level+1, Data = childOrDescendant.Data};
				}
			}
		}
	}
}
&lt;/pre&gt;
Here&#039;s how to use it:
&lt;pre lang=&quot;csharp&quot;&gt;class Program
{
	private static void Main(string[] args)
	{
		var q = from directory in new DirectoryInfo(@&quot;c:\&quot;)
					.FlattenHierarchyWithLevel(x =&gt; x.GetDirectories())
				select directory;

		foreach (var levelAndData in q.Take(10))
		{
			Console.WriteLine(levelAndData.Level + &quot; - &quot; + levelAndData.Data.Name);
		}

		Console.WriteLine(&quot;\nPress ENTER...&quot;);
		Console.ReadLine();
	}
}
&lt;/pre&gt;
You&#039;ll need to VB-ify it yourself. Hope it helps!</description>
		<content:encoded><![CDATA[<p>Hi Gary!</p>
<p>I did your homework (in C#) ;) I made a new class LevelAndData, which is used both internally in the new <code>FlattenHierarchyWithLevels</code> method and as the return type.</p>
<p>I think this does what you ask:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> LinqToHierarchical
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LevelAndData<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Level <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">public</span> T Data <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>LevelAndData<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;&gt;</span> FlattenHierarchyWithLevel<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> T node, Func<span style="color: #008000;">&lt;</span>T, IEnumerable<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;&gt;</span> getChildEnumerator<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		yield <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LevelAndData<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> <span style="color: #000000;">&#123;</span>Level <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, Data <span style="color: #008000;">=</span> node<span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>getChildEnumerator<span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var child <span style="color: #0600FF;">in</span> getChildEnumerator<span style="color: #000000;">&#40;</span>node<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var childOrDescendant <span style="color: #0600FF;">in</span> child.<span style="color: #0000FF;">FlattenHierarchyWithLevel</span><span style="color: #000000;">&#40;</span>getChildEnumerator<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					yield <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> LevelAndData<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#123;</span> Level <span style="color: #008000;">=</span> childOrDescendant.<span style="color: #0000FF;">Level</span><span style="color: #008000;">+</span><span style="color: #FF0000;">1</span>, Data <span style="color: #008000;">=</span> childOrDescendant.<span style="color: #0000FF;">Data</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Here&#8217;s how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var q <span style="color: #008000;">=</span> from directory <span style="color: #0600FF;">in</span> <span style="color: #008000;">new</span> DirectoryInfo<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;c:\&quot;</span><span style="color: #000000;">&#41;</span>
					.<span style="color: #0000FF;">FlattenHierarchyWithLevel</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">GetDirectories</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
				select directory<span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var levelAndData <span style="color: #0600FF;">in</span> q.<span style="color: #0000FF;">Take</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>levelAndData.<span style="color: #0000FF;">Level</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; - &quot;</span> <span style="color: #008000;">+</span> levelAndData.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\n</span>Press ENTER...&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You&#8217;ll need to VB-ify it yourself. Hope it helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Morris</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1200</link>
		<dc:creator>Gary Morris</dc:creator>
		<pubDate>Fri, 16 Sep 2011 04:22:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1200</guid>
		<description>Yes, the problem for the way I am doing it now is not knowing until runtime how deep the levels go.

I was a &quot;C&quot; programmer for more than a decade but have become much more comfortable using VB.net.

I like the idea of having recursive calls because then I dont have to code for each level, but am struggling with your suggestion of how to return the depth.

Would it be just add one to the current depth on each return?

Could you post a little snippet (in vb 2010) of how that would be done?

I am really intrigued by your concept of flatting the hiearachy. Seems much more elegant than the way I am doing it now but keeping track of which level I am in and reading the next node to see if there are any children. The way I am doing it now, I have to know ahead of time how many levels to program for. Ugh...

Any futher help would be very much appreciated.</description>
		<content:encoded><![CDATA[<p>Yes, the problem for the way I am doing it now is not knowing until runtime how deep the levels go.</p>
<p>I was a &#8220;C&#8221; programmer for more than a decade but have become much more comfortable using VB.net.</p>
<p>I like the idea of having recursive calls because then I dont have to code for each level, but am struggling with your suggestion of how to return the depth.</p>
<p>Would it be just add one to the current depth on each return?</p>
<p>Could you post a little snippet (in vb 2010) of how that would be done?</p>
<p>I am really intrigued by your concept of flatting the hiearachy. Seems much more elegant than the way I am doing it now but keeping track of which level I am in and reading the next node to see if there are any children. The way I am doing it now, I have to know ahead of time how many levels to program for. Ugh&#8230;</p>
<p>Any futher help would be very much appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aeinbu</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1199</link>
		<dc:creator>aeinbu</dc:creator>
		<pubDate>Wed, 14 Sep 2011 18:29:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1199</guid>
		<description>Hi Gary!

Putting the results in a list, would allow you to walk to next or previous node with the indexer. But part of your problem is that you don&#039;t have the depth/level of the original node.

Well, this article is really about flattening the hierarchy, so any information about depth or level in the hierarchy will be lost.

You can however modify my code, and add a level counter mechanism to it. The steps would be something like this:
1. Take in an aditional parameter to the FlattenHierarchy method. (int depth)
2. On both yield return statements you could return a new object that has both the depth+1 and the data to return.
3. Modify the calls to the FlattenHierarchy method to include current depth.

Hope this helps you on your way!</description>
		<content:encoded><![CDATA[<p>Hi Gary!</p>
<p>Putting the results in a list, would allow you to walk to next or previous node with the indexer. But part of your problem is that you don&#8217;t have the depth/level of the original node.</p>
<p>Well, this article is really about flattening the hierarchy, so any information about depth or level in the hierarchy will be lost.</p>
<p>You can however modify my code, and add a level counter mechanism to it. The steps would be something like this:<br />
1. Take in an aditional parameter to the FlattenHierarchy method. (int depth)<br />
2. On both yield return statements you could return a new object that has both the depth+1 and the data to return.<br />
3. Modify the calls to the FlattenHierarchy method to include current depth.</p>
<p>Hope this helps you on your way!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Morris</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1198</link>
		<dc:creator>Gary Morris</dc:creator>
		<pubDate>Wed, 14 Sep 2011 14:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1198</guid>
		<description>I should have given the additional level of the drive. It is the drive level that really complicates things:

E:\DVDs
–Awaydays
–Dog Days
–Die Hard Series
—-Die Hard 1
—-Die Hard 2
—-Die Hard 3
–Get Smart
–Happy Gilmore
F:\DVDs

I have tried using a recursive call down the tree and storing that in a List(of T), but the problem comes in trying to assign the Selected method to the List...

TreeView1.Selected = t_myDVDs.MovieName 

Should I store a List(of Nodes) perhaps?

By traversing the List instead of the tree, it would seem to make the &quot;Previous&quot; trip back up the tree less complicated, yes?

Please help. I have been fighting this for days.</description>
		<content:encoded><![CDATA[<p>I should have given the additional level of the drive. It is the drive level that really complicates things:</p>
<p>E:\DVDs<br />
–Awaydays<br />
–Dog Days<br />
–Die Hard Series<br />
—-Die Hard 1<br />
—-Die Hard 2<br />
—-Die Hard 3<br />
–Get Smart<br />
–Happy Gilmore<br />
F:\DVDs</p>
<p>I have tried using a recursive call down the tree and storing that in a List(of T), but the problem comes in trying to assign the Selected method to the List&#8230;</p>
<p>TreeView1.Selected = t_myDVDs.MovieName </p>
<p>Should I store a List(of Nodes) perhaps?</p>
<p>By traversing the List instead of the tree, it would seem to make the &#8220;Previous&#8221; trip back up the tree less complicated, yes?</p>
<p>Please help. I have been fighting this for days.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Morris</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-1197</link>
		<dc:creator>Gary Morris</dc:creator>
		<pubDate>Tue, 13 Sep 2011 20:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-1197</guid>
		<description>What I cant find is a way to traverse a tree with a &quot;Next&quot; and &quot;Previous&quot; button.

I can do it to a certian degree, but it has problems.

The problem occurs when you step into a child. For example.

+MyDVDs
--Awaydays
--Dog Days
--Die Hard Series
----Die Hard 1
----Die Hard 2
----Die Hard 3
--Get Smart
--Happy Gilmore

How can I click &quot;Next&quot; and have it traverse down the tree, one step at a time, and then at any point, traverse back up the tree?

Please help.</description>
		<content:encoded><![CDATA[<p>What I cant find is a way to traverse a tree with a &#8220;Next&#8221; and &#8220;Previous&#8221; button.</p>
<p>I can do it to a certian degree, but it has problems.</p>
<p>The problem occurs when you step into a child. For example.</p>
<p>+MyDVDs<br />
&#8211;Awaydays<br />
&#8211;Dog Days<br />
&#8211;Die Hard Series<br />
&#8212;-Die Hard 1<br />
&#8212;-Die Hard 2<br />
&#8212;-Die Hard 3<br />
&#8211;Get Smart<br />
&#8211;Happy Gilmore</p>
<p>How can I click &#8220;Next&#8221; and have it traverse down the tree, one step at a time, and then at any point, traverse back up the tree?</p>
<p>Please help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-952</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 19 Jan 2011 17:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-952</guid>
		<description>Converted to vb.net...

Imports System.Runtime.CompilerServices
Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim ctrls = From ctrl In CType(Me, Control).FlattenHierarchy(Function(x As Control) x.Controls.Cast(Of Control)())
        Select ctrl

        Dim directories = From directory In New DirectoryInfo(&quot;C:\temp&quot;).FlattenHierarchy(Function(x As DirectoryInfo) x.GetDirectories())
        Select directory.FullName

    End Sub
End Class


Module X
     _
    Public Function FlattenHierarchy(Of T)(ByVal node As T, ByVal getChildEnumerator As System.Func(Of T, IEnumerable(Of T))) As IEnumerable(Of T)
        Dim q As New List(Of T) From {node}
        Dim children As IEnumerable(Of T) = getChildEnumerator(node)

        If children IsNot Nothing Then
            For Each child As T In children
                For Each childOrDescendant In child.FlattenHierarchy(getChildEnumerator)
                    q.Add(childOrDescendant)
                Next
            Next
        End If

        Return q
    End Function
End Module</description>
		<content:encoded><![CDATA[<p>Converted to vb.net&#8230;</p>
<p>Imports System.Runtime.CompilerServices<br />
Imports System.IO</p>
<p>Public Class Form1</p>
<p>    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load</p>
<p>        Dim ctrls = From ctrl In CType(Me, Control).FlattenHierarchy(Function(x As Control) x.Controls.Cast(Of Control)())<br />
        Select ctrl</p>
<p>        Dim directories = From directory In New DirectoryInfo(&#8220;C:\temp&#8221;).FlattenHierarchy(Function(x As DirectoryInfo) x.GetDirectories())<br />
        Select directory.FullName</p>
<p>    End Sub<br />
End Class</p>
<p>Module X<br />
     _<br />
    Public Function FlattenHierarchy(Of T)(ByVal node As T, ByVal getChildEnumerator As System.Func(Of T, IEnumerable(Of T))) As IEnumerable(Of T)<br />
        Dim q As New List(Of T) From {node}<br />
        Dim children As IEnumerable(Of T) = getChildEnumerator(node)</p>
<p>        If children IsNot Nothing Then<br />
            For Each child As T In children<br />
                For Each childOrDescendant In child.FlattenHierarchy(getChildEnumerator)<br />
                    q.Add(childOrDescendant)<br />
                Next<br />
            Next<br />
        End If</p>
<p>        Return q<br />
    End Function<br />
End Module</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# alternative for Ruby&#8217;s acts_as_tree, part 2 • Onderweg Blog</title>
		<link>http://blog.einbu.no/2009/07/traverse-a-hierarchy-with-linq-to-hierarchical/comment-page-1/#comment-948</link>
		<dc:creator>C# alternative for Ruby&#8217;s acts_as_tree, part 2 • Onderweg Blog</dc:creator>
		<pubDate>Mon, 08 Nov 2010 22:51:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.einbu.no/?p=353#comment-948</guid>
		<description>[...] Traverse a hierarchical structure with LINQ-to-Hierarchical (or how to flatten a tree with Linq).          Filed in C# .NET, Theory  Tags: C#, extension methods, language features, ruby  1 Comment &#187; [...]</description>
		<content:encoded><![CDATA[<p>[...] Traverse a hierarchical structure with LINQ-to-Hierarchical (or how to flatten a tree with Linq).          Filed in C# .NET, Theory  Tags: C#, extension methods, language features, ruby  1 Comment &#187; [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

