Files
Umbraco-CMS/umbraco.MacroEngines.Juno/RazorDynamicNode/ExtensionMethods.cs
agrath@gmail.com 603a12c5a0 Split umbraco.MacroEngines.Juno into two subfolders (namespaces remain the same)
RazorCore contains all the core razor engine implementation
RazorDynamicNode contains all the DynamicNode functionality and associated support files
2011-02-24 16:05:54 -13:00

27 lines
915 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace umbraco.MacroEngines
{
public static class ExtensionMethods
{
public static IEnumerable<TSource> Map<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> selectorFunction,
Func<TSource, IEnumerable<TSource>> getChildrenFunction)
{
// Add what we have to the stack
var flattenedList = source.Where(selectorFunction);
// Go through the input enumerable looking for children,
// and add those if we have them
foreach (TSource element in source)
{
flattenedList = flattenedList.Concat(getChildrenFunction(element).Map(selectorFunction, getChildrenFunction));
}
return flattenedList;
}
}
}