private static bool EvaluateBitMaskFilter(BitMaskFilter bitMaskFilter, IReadOnlyPropertyBag propertyBag, bool shouldThrow) { object obj = null; try { obj = propertyBag[bitMaskFilter.Property]; } catch (PropertyErrorException) { if (shouldThrow) { throw; } return(false); } if (EvaluatableFilter.IsPropertyError(propertyBag, bitMaskFilter.Property, shouldThrow)) { return(false); } if (bitMaskFilter.IsNonZero) { return(0UL != ((ulong)obj & bitMaskFilter.Mask)); } return(0UL == ((ulong)obj & bitMaskFilter.Mask)); }
private static bool EvaluateComparisonFilter(ComparisonFilter comparisonFilter, IReadOnlyPropertyBag propertyBag, bool shouldThrow) { object obj; try { obj = propertyBag[comparisonFilter.Property]; } catch (PropertyErrorException) { if (shouldThrow) { throw; } return(false); } PropertyError propertyError = obj as PropertyError; if (propertyError != null) { if (shouldThrow) { throw PropertyErrorException.FromPropertyErrorsInternal(new PropertyError[] { propertyError }); } return(false); } else { if (EvaluatableFilter.IsPropertyError(propertyBag, comparisonFilter.Property, shouldThrow)) { return(false); } switch (comparisonFilter.ComparisonOperator) { case ComparisonOperator.Equal: if (comparisonFilter.PropertyValue is Participant) { return(Participant.HasSameEmail(comparisonFilter.PropertyValue as Participant, obj as Participant, false)); } if (obj is MultiValuedProperty <string> && comparisonFilter.PropertyValue is string) { MultiValuedProperty <string> multiValuedProperty = obj as MultiValuedProperty <string>; if (multiValuedProperty.Count == 1) { return(multiValuedProperty[0].Equals(comparisonFilter.PropertyValue)); } } if (obj is SmtpAddress && comparisonFilter.PropertyValue is EmailAddress) { return(obj.Equals((comparisonFilter.PropertyValue as EmailAddress).Address)); } return(obj.Equals(comparisonFilter.PropertyValue)); case ComparisonOperator.NotEqual: return(!obj.Equals(comparisonFilter.PropertyValue)); case ComparisonOperator.LessThan: if (comparisonFilter.PropertyValue is ExDateTime) { return((ExDateTime)obj < (ExDateTime)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is int) { return((int)obj < (int)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is long) { return((long)obj < (long)comparisonFilter.PropertyValue); } throw new InvalidOperationException("Only int, long, and ExDateTime supported for ComparisonFilter <"); case ComparisonOperator.LessThanOrEqual: if (comparisonFilter.PropertyValue is ExDateTime) { return((ExDateTime)obj <= (ExDateTime)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is int) { return((int)obj <= (int)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is long) { return((long)obj <= (long)comparisonFilter.PropertyValue); } throw new InvalidOperationException("Only int, long, and ExDateTime supported for ComparisonFilter <="); case ComparisonOperator.GreaterThan: if (comparisonFilter.PropertyValue is ExDateTime) { return((ExDateTime)obj > (ExDateTime)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is int) { return((int)obj > (int)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is long) { return((long)obj > (long)comparisonFilter.PropertyValue); } throw new InvalidOperationException("Only int, long, and ExDateTime supported for ComparisonFilter >"); case ComparisonOperator.GreaterThanOrEqual: if (comparisonFilter.PropertyValue is ExDateTime) { return((ExDateTime)obj >= (ExDateTime)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is int) { return((int)obj >= (int)comparisonFilter.PropertyValue); } if (comparisonFilter.PropertyValue is long) { return((long)obj >= (long)comparisonFilter.PropertyValue); } throw new InvalidOperationException("Only int, long, and ExDateTime supported for ComparisonFilter >="); default: throw new InvalidOperationException("Unsupported ComparisonOperator: " + ((int)comparisonFilter.ComparisonOperator).ToString()); } } bool result; return(result); }
private static bool EvaluateTextFilter(TextFilter textFilter, IReadOnlyPropertyBag propertyBag, bool shouldThrow) { object obj = null; try { obj = propertyBag[textFilter.Property]; } catch (PropertyErrorException) { if (shouldThrow) { throw; } return(false); } if (EvaluatableFilter.IsPropertyError(propertyBag, textFilter.Property, shouldThrow)) { return(false); } if (obj == null) { return(false); } string text = (string)obj; StringComparison comparisonType; if (textFilter.MatchFlags == MatchFlags.IgnoreCase) { comparisonType = StringComparison.OrdinalIgnoreCase; } else { if (textFilter.MatchFlags != MatchFlags.Default) { throw new NotSupportedException(); } comparisonType = StringComparison.Ordinal; } switch (textFilter.MatchOptions) { case MatchOptions.FullString: return(text.Equals(textFilter.Text, comparisonType)); case MatchOptions.SubString: return(text.IndexOf(textFilter.Text, comparisonType) >= 0); case MatchOptions.Prefix: return(text.StartsWith(textFilter.Text, comparisonType)); case MatchOptions.Suffix: return(text.EndsWith(textFilter.Text, comparisonType)); case MatchOptions.PrefixOnWords: return(text.StartsWith(textFilter.Text, comparisonType) && (text.Length == textFilter.Text.Length || text[textFilter.Text.Length] == '.')); default: throw new NotSupportedException(); } bool result; return(result); }