comparison MetroWpf/MetroWpf.Framework/Extensions/LinqExtensions.cs @ 15:060f02cd4591

Initial commit, pre airport work
author stevenh7776 stevenhollidge@hotmail.com
date Mon, 12 Mar 2012 23:05:21 +0800
parents
children
comparison
equal deleted inserted replaced
14:741981715d94 15:060f02cd4591
1 using System;
2 using System.Collections.Generic;
3 using System.Linq.Expressions;
4
5 namespace MetroWpf
6 {
7 public static class LinqExtensions
8 {
9 #region · Extensions ·
10
11 /// <summary>
12 /// Traverses the specified source.
13 /// </summary>
14 /// <typeparam name="T"></typeparam>
15 /// <param name="source">The source.</param>
16 /// <param name="fnRecurse">The fn recurse.</param>
17 /// <returns></returns>
18 public static IEnumerable<T> Traverse<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> fnRecurse)
19 {
20 foreach (T item in source)
21 {
22 yield return item;
23
24 IEnumerable<T> seqRecurse = fnRecurse(item);
25
26 if (seqRecurse != null)
27 {
28 foreach (T itemRecurse in Traverse(seqRecurse, fnRecurse))
29 {
30 yield return itemRecurse;
31 }
32 }
33 }
34 }
35
36 #endregion
37 }
38 }