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 {
00010 public abstract class ItemFilter : IPipeline, IDisposable
00011 {
00015 public abstract bool Match(ContentItem item);
00016
00019 public virtual void Filter(IList<ContentItem> items)
00020 {
00021 using (this)
00022 {
00023 for (int i = items.Count - 1; i >= 0; i--)
00024 if (!Match(items[i]))
00025 items.RemoveAt(i);
00026 }
00027 }
00028
00032 public virtual IEnumerable<T> Pipe<T>(IEnumerable<T> items)
00033 where T : ContentItem
00034 {
00035 using (this)
00036 {
00037 foreach (T item in items)
00038 if (Match(item))
00039 yield return item;
00040 }
00041 }
00042
00046 public virtual IEnumerable<ContentItem> Pipe(IEnumerable<ContentItem> items)
00047 {
00048 return Pipe<ContentItem>(items);
00049 }
00050
00054 public static void Filter(IList<ContentItem> items, ItemFilter filter)
00055 {
00056 filter.Filter(items);
00057 }
00058
00059 #region IDisposable Members
00060
00062 public virtual void Dispose()
00063 {
00064
00065 }
00066
00067 #endregion
00068 }
00069 }