/// <summary> /// Initializes FilterExpressionWrapper with given filterString. /// </summary> public FilterExpressionWrapper(string filterString) { ValidateArg.NotNullOrEmpty(filterString, "filterString"); this.FilterString = filterString; try { this.filterExpression = FilterExpression.Parse(filterString); } catch (FormatException ex) { this.ParseError = ex.Message; } }
/// <summary> /// Initializes FilterExpressionWrapper with given filterString and options. /// </summary> public FilterExpressionWrapper(string filterString, FilterOptions options) { ValidateArg.NotNullOrEmpty(filterString, "filterString"); this.FilterString = filterString; this.FilterOptions = options; try { // We prefer fast filter when it's available. this.filterExpression = FilterExpression.Parse(filterString, out this.fastFilter); if (UseFastFilter) { this.filterExpression = null; // Property value regex is only supported for fast filter, // so we ignore it if no fast filter is constructed. // TODO: surface an error message to suer. var regexString = options?.FilterRegEx; if (!string.IsNullOrEmpty(regexString)) { Debug.Assert(options.FilterRegExReplacement != null ? options.FilterRegEx != null : true); this.fastFilter.PropertyValueRegex = new Regex(regexString, RegexOptions.Compiled); this.fastFilter.PropertyValueRegexReplacement = options.FilterRegExReplacement; } } } catch (FormatException ex) { this.ParseError = ex.Message; } catch (ArgumentException ex) { this.fastFilter = null; this.ParseError = ex.Message; } }