Filters are a powerful boolean algebra (AND-OR-NOT) based mechanism, which enables the composition of virtually any type of logical expression (predicate). The abstraction for a filter is defined by the INFilter interface, a core implementation of which can be found in the NFilter class.
Primitive filters are filters, which do not aggregate other filters. The Nevron System Layer contains the following set of predefined primitive filters:
Filter type |
Description |
Object Type Filters |
NAssignableFromTypeFilter |
return true, if the specified object type can be assigned to the target type |
NExactTypeMatchFilter |
returns true, if the specified object type is the target type |
NInstanceOfTypeFilter |
returns true, if the specified object is an instance of the target type |
Numeric Filters |
NDoubleInRangeFilter |
returns true, if the specified object can be converted to double and is in the range [begin, end] |
NInt32InRangeFilter |
returns true, if the specified object can be converted to int and is in the range [begin, end] |
Each individual Nevron product typically defines additional primitive filters.
Since filter logic is AND-OR-NOT based, filter expressions are constructed with the help of the NAndFilter, NOrFilter and NNotFilter classes. The result of the first two is a logical AND/OR of the result of the filters they contain. If an AND or OR filter does not contain any filters it will always evaluate to false. The NNotFilter inverts the result of the filter it contains.
The following example demonstrates a simple type filter and an AND expression filter:
C# |
Copy Code
|
// filters only objects derived from MyBaseType, which do not implement MyInterface
NAndFilter andFilter = new NAndFilter();
andFilter.Add(new NInstanceOfTypeFilter(typeof(MyBaseType)));
andFilter.Add(new NNotFilter(new NInstanceOfTypeFilter(typeof(MyInterface))));
|
Visual Basic |
Copy Code
|
' filters only objects derived from MyBaseType, which do not implement MyInterface
Dim andFilter As New NAndFilter
andFilter.Add(New NInstanceOfTypeFilter(GetType(MyBaseType)))
andFilter.Add(New NNotFilter(New NInstanceOfTypeFilter(GetType(MyInterface))))
|