You could start with implementations of something like this for each filter:
public interface IFilter<T>
{
bool Matches(T itemToMatch);
}
For the sub-layer of filters (Condition 1...n) you could use a Composite 'all' filter like this; all of the IFilter<T>
implementations contained have to match for the composite to say it matches:
public class AllMatchingCompositeFilter : List<IFilter<MyClass>>, IFilter<MyClass>
{
public bool Matches(T itemToMatch)
{
return this.All(filter => filter.Matches(itemToFilter));
}
}
...and for the top-level of filters (if Condition n doesn't match check Condition n+1) you could combine multiple AllMatchingCompositeFilter
s in an 'any' filter like this; it executes each of its IFilter<T>
s in the order they were added and returns true if any of them match:
public class AnyMatchingCompositeFilter : List<IFilter<MyClass>>, IFilter<MyClass>
{
public bool Matches(T itemToMatch)
{
return this.Any(filter => filter.Matches(itemToFilter));
}
}