I have an entity called Category and the entity contains a IEnumerable called ChildCategories. A category can have these child categories which can have it\'s own child cate
There where some problems with casperOnes code. This works:
public static IEnumerable Flatten(this IEnumerable source, Func> childrenSelector)
{
// Do standard error checking here.
// Cycle through all of the items.
foreach (T item in source)
{
// Yield the item.
yield return item;
// Yield all of the children.
foreach (T child in childrenSelector(item).Flatten(childrenSelector))
{
// Yield the item.
yield return child;
}
}
}