Пример #1
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);
                }
            }
        }
Пример #2
0
 private static void GenerateInfixString(QueryFilter filter, StringBuilder sb, FilterSchema filterSchema)
 {
     if (filter is CompositeFilter)
     {
         sb.Append("(");
         CompositeFilter compositeFilter = (CompositeFilter)filter;
         int             filterCount     = compositeFilter.FilterCount;
         for (int i = 0; i < filterCount - 1; i++)
         {
             sb.Append("(");
             QueryFilter.GenerateInfixString(compositeFilter.Filters[i], sb, filterSchema);
             sb.Append(") ");
             if (filter is AndFilter)
             {
                 sb.Append(filterSchema.And);
             }
             else if (filter is OrFilter)
             {
                 sb.Append(filterSchema.Or);
             }
             sb.Append(" ");
         }
         sb.Append("(");
         QueryFilter.GenerateInfixString(compositeFilter.Filters[filterCount - 1], sb, filterSchema);
         sb.Append("))");
         return;
     }
     if (filter is NotFilter)
     {
         NotFilter notFilter = filter as NotFilter;
         sb.Append(filterSchema.Not);
         sb.Append("(");
         QueryFilter.GenerateInfixString(notFilter.Filter, sb, filterSchema);
         sb.Append(")");
         return;
     }
     if (filter is TextFilter)
     {
         TextFilter textFilter   = filter as TextFilter;
         string     propertyName = filterSchema.GetPropertyName(textFilter.Property.Name);
         if (!string.IsNullOrEmpty(propertyName))
         {
             sb.Append(propertyName);
             sb.Append(filterSchema.Like);
         }
         if (textFilter.MatchOptions == MatchOptions.FullString || textFilter.MatchOptions == MatchOptions.ExactPhrase || filterSchema.SupportQuotedPrefix)
         {
             sb.Append(filterSchema.QuotationMark);
         }
         if (textFilter.MatchOptions == MatchOptions.Suffix || textFilter.MatchOptions == MatchOptions.SubString)
         {
             sb.Append("*");
         }
         sb.Append(filterSchema.EscapeStringValue(textFilter.Text));
         if (textFilter.MatchOptions == MatchOptions.Prefix || textFilter.MatchOptions == MatchOptions.SubString || textFilter.MatchOptions == MatchOptions.PrefixOnWords)
         {
             sb.Append("*");
         }
         if (textFilter.MatchOptions == MatchOptions.FullString || textFilter.MatchOptions == MatchOptions.ExactPhrase || filterSchema.SupportQuotedPrefix)
         {
             sb.Append(filterSchema.QuotationMark);
             return;
         }
     }
     else
     {
         if (filter is ComparisonFilter)
         {
             ComparisonFilter comparisonFilter = filter as ComparisonFilter;
             sb.Append(filterSchema.GetPropertyName(comparisonFilter.Property.Name));
             sb.Append(filterSchema.GetRelationalOperator(comparisonFilter.ComparisonOperator));
             sb.Append(filterSchema.QuotationMark);
             sb.Append(filterSchema.EscapeStringValue(comparisonFilter.PropertyValue));
             sb.Append(filterSchema.QuotationMark);
             return;
         }
         if (filter is ExistsFilter)
         {
             sb.Append(filterSchema.GetExistsFilter(filter as ExistsFilter));
             return;
         }
         if (filter is FalseFilter)
         {
             sb.Append(filterSchema.GetFalseFilter());
         }
     }
 }
Пример #3
0
        public override bool Equals(object obj)
        {
            TextFilter textFilter = obj as TextFilter;

            return(textFilter != null && base.MatchFlags == textFilter.MatchFlags && base.MatchOptions == textFilter.MatchOptions && this.text == textFilter.text && base.Equals(obj));
        }