Go to the documentation of this file.00001 using System;
00002 using System.Collections.Generic;
00003 using N2.Persistence.Finder;
00004
00005 namespace N2.Collections
00006 {
00010 public class ParentFilter : ItemFilter
00011 {
00012 ContentItem parent;
00013 private int? parentID;
00014
00015 public ParentFilter(int parentID)
00016 {
00017 this.parentID = parentID;
00018 }
00019
00020 public ParentFilter(ContentItem parent)
00021 {
00022 if (parent == null)
00023 throw new ArgumentNullException("parent");
00024
00025 this.parent = parent;
00026 this.parentID = parent.ID;
00027 }
00028
00029 public override bool Match(ContentItem item)
00030 {
00031 if (parent != null)
00032 {
00033 return item != parent
00034 && Utility.GetTrail(item).StartsWith(Utility.GetTrail(parent));
00035 }
00036
00037 while ((item = item.Parent) != null)
00038 {
00039 if (item.ID == parentID)
00040 return true;
00041 }
00042 return false;
00043 }
00044
00045 #region Static Methods
00046 public static void Filter(IList<ContentItem> items, ContentItem parent)
00047 {
00048 Filter(items, new ParentFilter(parent));
00049 }
00050 public static void Filter(IList<ContentItem> items, int parentID)
00051 {
00052 Filter(items, new ParentFilter(parentID));
00053 }
00054 #endregion
00055 }
00056 }