Mercurial > silverbladetech
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MetroWpf/MetroWpf.Framework/Extensions/LinqExtensions.cs Mon Mar 12 23:05:21 2012 +0800 @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace MetroWpf +{ + public static class LinqExtensions + { + #region · Extensions · + + /// <summary> + /// Traverses the specified source. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="source">The source.</param> + /// <param name="fnRecurse">The fn recurse.</param> + /// <returns></returns> + public static IEnumerable<T> Traverse<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> fnRecurse) + { + foreach (T item in source) + { + yield return item; + + IEnumerable<T> seqRecurse = fnRecurse(item); + + if (seqRecurse != null) + { + foreach (T itemRecurse in Traverse(seqRecurse, fnRecurse)) + { + yield return itemRecurse; + } + } + } + } + + #endregion + } +}