Beispiel #1
0
 internal CSharpFilter(CSharpFilter <T> .MatchDelegate matchDelegate)
 {
     if (matchDelegate == null)
     {
         throw new ArgumentNullException("matchDelegate");
     }
     this.matchDelegate = matchDelegate;
 }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            CSharpFilter <T> csharpFilter = obj as CSharpFilter <T>;

            return(csharpFilter != null && !(csharpFilter.GetType() != base.GetType()) && object.ReferenceEquals(this.matchDelegate, csharpFilter.matchDelegate));
        }
Beispiel #3
0
        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);
        }