Go to the documentation of this file.00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004
00005 namespace N2.Collections
00006 {
00011 public class RecursiveFinder
00012 {
00018 public IEnumerable<T> Find<T>(ContentItem root, int recursionDepth)
00019 where T : class
00020 {
00021 List<T> items = new List<T>();
00022 AppendRecursive(root, items, recursionDepth);
00023 return items;
00024 }
00025
00032 public IEnumerable<T> Find<T>(ContentItem root, int recursionDepth, params Type[] except)
00033 where T : class
00034 {
00035 List<T> items = new List<T>();
00036 AppendRecursive(root, items, recursionDepth, except);
00037 return items;
00038 }
00039
00040 private void AppendRecursive<T>(ContentItem item, List<T> items, int depth, params Type[] except)
00041 where T : class
00042 {
00043 if (item is T)
00044 items.Add(item as T);
00045
00046 if (depth <= 0)
00047 return;
00048
00049 foreach (ContentItem child in item.Children)
00050 {
00051 if (Is(child, except))
00052 continue;
00053
00054 AppendRecursive(child, items, depth - 1);
00055 }
00056 }
00057
00058 private static bool Is(ContentItem child, Type[] except)
00059 {
00060 foreach (Type t in except)
00061 if (t.IsAssignableFrom(child.GetContentType()))
00062 return true;
00063 return false;
00064 }
00065 }
00066 }