public NearFilter(uint distance, bool ordered, AndFilter filter) { this.distance = distance; this.ordered = ordered; this.filter = filter; }
internal static QueryFilter SimplifyFilter(QueryFilter filter) { if (filter == null) { return(null); } if (filter.IsAtomic) { return(filter); } if (!(filter is NotFilter) && !(filter is CompositeFilter)) { return(filter); } NotFilter notFilter = filter as NotFilter; if (notFilter != null) { QueryFilter filter2 = notFilter.Filter; if (filter2.IsAtomic) { return(filter); } if (filter2 is NotFilter) { return(QueryFilter.SimplifyFilter(((NotFilter)filter2).Filter)); } if (filter2 is CompositeFilter) { CompositeFilter compositeFilter = (CompositeFilter)filter2; QueryFilter[] array = new QueryFilter[compositeFilter.Filters.Count]; for (int i = 0; i < array.Length; i++) { array[i] = QueryFilter.NotFilter(compositeFilter.Filters[i]); } if (filter2 is AndFilter) { return(QueryFilter.SimplifyFilter(QueryFilter.OrTogether(array))); } if (filter2 is OrFilter) { return(QueryFilter.SimplifyFilter(QueryFilter.AndTogether(array))); } } if (filter2 is ComparisonFilter) { ComparisonFilter comparisonFilter = (ComparisonFilter)filter2; ComparisonOperator comparisonOperator; switch (comparisonFilter.ComparisonOperator) { case ComparisonOperator.Equal: comparisonOperator = ComparisonOperator.NotEqual; break; case ComparisonOperator.NotEqual: comparisonOperator = ComparisonOperator.Equal; break; case ComparisonOperator.LessThan: comparisonOperator = ComparisonOperator.GreaterThanOrEqual; break; case ComparisonOperator.LessThanOrEqual: comparisonOperator = ComparisonOperator.GreaterThan; break; case ComparisonOperator.GreaterThan: comparisonOperator = ComparisonOperator.LessThanOrEqual; break; case ComparisonOperator.GreaterThanOrEqual: comparisonOperator = ComparisonOperator.LessThan; break; default: return(filter); } return(new ComparisonFilter(comparisonOperator, comparisonFilter.Property, comparisonFilter.PropertyValue)); } return(QueryFilter.NotFilter(QueryFilter.SimplifyFilter(filter2))); } else { AndFilter andFilter = filter as AndFilter; if (andFilter != null) { return(QueryFilter.SimplifyCompositeFilter <AndFilter, OrFilter>(andFilter)); } OrFilter orFilter = filter as OrFilter; if (orFilter != null) { return(QueryFilter.SimplifyCompositeFilter <OrFilter, AndFilter>(orFilter)); } return(filter); } }
public static bool FilterMatches(QueryFilter filter, IReadOnlyPropertyBag obj, Func <PropertyDefinition, object> getValueDelegate) { if (filter == null) { throw new ArgumentNullException("filter"); } if (getValueDelegate == null && obj == null) { throw new ArgumentNullException("getValueDelegate && obj"); } NotFilter notFilter = filter as NotFilter; if (notFilter != null) { return(!OpathFilterEvaluator.FilterMatches(notFilter.Filter, obj, getValueDelegate)); } AndFilter andFilter = filter as AndFilter; if (andFilter != null) { foreach (QueryFilter filter2 in andFilter.Filters) { if (!OpathFilterEvaluator.FilterMatches(filter2, obj, getValueDelegate)) { return(false); } } return(true); } OrFilter orFilter = filter as OrFilter; if (orFilter != null) { foreach (QueryFilter filter3 in orFilter.Filters) { if (OpathFilterEvaluator.FilterMatches(filter3, obj, getValueDelegate)) { return(true); } } return(false); } SinglePropertyFilter singlePropertyFilter = filter as SinglePropertyFilter; if (singlePropertyFilter != null) { SimpleProviderPropertyDefinition simpleProviderPropertyDefinition = singlePropertyFilter.Property as SimpleProviderPropertyDefinition; if (simpleProviderPropertyDefinition != null && simpleProviderPropertyDefinition.IsFilterOnly) { throw new FilterOnlyAttributesException(simpleProviderPropertyDefinition.Name); } object obj2 = (obj != null) ? obj[singlePropertyFilter.Property] : getValueDelegate(singlePropertyFilter.Property); if (OpathFilterEvaluator.IsNullOrEmpty(obj2)) { return(OpathFilterEvaluator.FilterMatchesValue(singlePropertyFilter, null)); } ICollection collection = obj2 as ICollection; if (collection != null) { foreach (object value in collection) { if (OpathFilterEvaluator.FilterMatchesValue(singlePropertyFilter, value)) { return(true); } } return(false); } return(OpathFilterEvaluator.FilterMatchesValue(singlePropertyFilter, obj2)); } else { CSharpFilter <IReadOnlyPropertyBag> csharpFilter = filter as CSharpFilter <IReadOnlyPropertyBag>; if (csharpFilter != null) { if (obj == null) { throw new ArgumentNullException("obj"); } return(csharpFilter.Match(obj)); } else { if (filter is TrueFilter) { return(true); } if (filter is FalseFilter) { return(false); } throw new NotSupportedException("The specified filter type \"" + filter.GetType().Name + "\" is currently not supported."); } } bool result; return(result); }