예제 #1
0
        public override bool Equals(object obj)
        {
            GenericBitMaskFilter genericBitMaskFilter = obj as GenericBitMaskFilter;

            return(genericBitMaskFilter != null && this.mask == genericBitMaskFilter.mask && base.Equals(obj));
        }
예제 #2
0
        private static bool FilterMatchesValue(SinglePropertyFilter filter, object value)
        {
            if (filter is ExistsFilter)
            {
                return(null != value);
            }
            if (filter is GenericBitMaskFilter)
            {
                ulong num;
                try
                {
                    num = Convert.ToUInt64(value);
                }
                catch (InvalidCastException)
                {
                    return(false);
                }
                GenericBitMaskFilter genericBitMaskFilter = filter as GenericBitMaskFilter;
                if (genericBitMaskFilter is BitMaskOrFilter)
                {
                    return(0UL != (genericBitMaskFilter.Mask & num));
                }
                if (genericBitMaskFilter is BitMaskAndFilter)
                {
                    return(genericBitMaskFilter.Mask == (genericBitMaskFilter.Mask & num));
                }
            }
            if (filter is TextFilter)
            {
                TextFilter textFilter = filter as TextFilter;
                string     text       = textFilter.Text ?? string.Empty;
                string     text2      = (value == null) ? string.Empty : value.ToString();
                if (string.IsNullOrEmpty(text2))
                {
                    return(string.IsNullOrEmpty(text));
                }
                StringComparison stringComparison = OpathFilterEvaluator.GetStringComparison(textFilter.MatchFlags);
                switch (textFilter.MatchOptions)
                {
                case MatchOptions.FullString:
                    return(text2.Equals(text, stringComparison));

                case MatchOptions.SubString:
                case MatchOptions.ExactPhrase:
                    return(-1 != text2.IndexOf(text, stringComparison));

                case MatchOptions.Prefix:
                    return(text2.StartsWith(text, stringComparison));

                case MatchOptions.Suffix:
                    return(text2.EndsWith(text, stringComparison));

                case MatchOptions.WildcardString:
                    return(OpathFilterEvaluator.MatchesWildcardString(text, text2, stringComparison));
                }
                throw new NotSupportedException("Not a currently supported Match Option: " + textFilter.MatchOptions);
            }
            else
            {
                if (!(filter is ComparisonFilter))
                {
                    throw new NotSupportedException("The specified filter type \"" + filter.GetType().Name + "\" is currently not supported.");
                }
                ComparisonFilter comparisonFilter = filter as ComparisonFilter;
                object           obj = ValueConvertor.ConvertValue(comparisonFilter.PropertyValue, comparisonFilter.Property.Type, null);
                switch (comparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    return(OpathFilterEvaluator.Equals(obj, value, StringComparison.OrdinalIgnoreCase));

                case ComparisonOperator.NotEqual:
                    return(!OpathFilterEvaluator.Equals(obj, value, StringComparison.OrdinalIgnoreCase));

                case ComparisonOperator.LessThan:
                    return(0 < Comparer.Default.Compare(obj, value));

                case ComparisonOperator.LessThanOrEqual:
                    return(0 <= Comparer.Default.Compare(obj, value));

                case ComparisonOperator.GreaterThan:
                    return(0 > Comparer.Default.Compare(obj, value));

                case ComparisonOperator.GreaterThanOrEqual:
                    return(0 >= Comparer.Default.Compare(obj, value));

                default:
                    throw new NotSupportedException("Not a currently supported comparison operator: " + comparisonFilter.ComparisonOperator);
                }
            }
        }