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 class CompositeFilter : ItemFilter
00011 {
00012 private ItemFilter[] filters;
00013
00014 public CompositeFilter(params ItemFilter[] filters)
00015 {
00016 this.filters = filters ?? new ItemFilter[0];
00017 }
00018
00019 public CompositeFilter(IEnumerable<ItemFilter> filters)
00020 {
00021 this.filters = new List<ItemFilter>(filters).ToArray();
00022 }
00023
00027 public ItemFilter[] Filters
00028 {
00029 get { return filters; }
00030 set { filters = value; }
00031 }
00032
00033 public override bool Match(ContentItem item)
00034 {
00035 foreach (ItemFilter filter in filters)
00036 if (!filter.Match(item))
00037 return false;
00038 return true;
00039 }
00040
00041 public static ItemFilter Wrap(IList<ItemFilter> filters)
00042 {
00043 if (filters == null || filters.Count == 0)
00044 return new NullFilter();
00045 else if (filters.Count == 1)
00046 return filters[0];
00047 else
00048 return new CompositeFilter(filters);
00049 }
00050
00051 public static ItemFilter Wrap(params ItemFilter[] filters)
00052 {
00053 return Wrap((IList<ItemFilter>)filters);
00054 }
00055 }
00056 }