/// <summary> /// Tests the predicate on an item</summary> /// <param name="searchItem">Item in which searchable elements should be queried</param> /// <param name="matchList">Resulting list of matching elements from within searchItem</param> /// <returns>True iff the item matches the predicate</returns> public bool Test(object searchItem, out IList <IQueryMatch> matchList) { matchList = null; IQueryable query = GetQueryable(searchItem); if (query != null) { // execute the query against domNode's Properties - foreach statement will iterate for each match foreach (object queryMatch in query) { // The tests below are NOT the match test...each queryMatch *is* a bona-fide match. // Rather, the if statement below confirms a valid 'match pattern' was created, which // can be used later to perform a replace operation. IQueryMatch candidate = CreatePredicateMatch(searchItem, queryMatch); if (MatchPattern == null || MatchPattern.Matches(candidate)) { if (matchList == null) { matchList = new List <IQueryMatch>(); } matchList.Add(candidate); } } } // success based on whether a match list was created or not return(matchList != null); }
/// <summary> /// Applies replacement on the query item data, using numerical replacement pattern</summary> /// <param name="itemToMatch">Query item to modify</param> /// <param name="replaceWith">Number to apply in the query item data, in place of matching number</param> public void Replace(IQueryMatch itemToMatch, object replaceWith) { // Make sure both itemToMatch and replaceWith are convertible, as attempting a convert that will fail // throws an exception, which is time-costly if (IsConvertibleToDouble(itemToMatch.GetValue()) && IsConvertibleToDouble(replaceWith)) { Double newValue = Convert.ToDouble(replaceWith); itemToMatch.SetValue(newValue); } }
/// <summary> /// Tests whether the specified query item matches the numerical replacement pattern</summary> /// <param name="itemToMatch">Query item to test</param> /// <returns>True iff match successful</returns> public bool Matches(IQueryMatch itemToMatch) { return IsConvertibleToDouble(itemToMatch.GetValue()); }
/// <summary> /// Applies replacement on the query item data, using the string replacement pattern</summary> /// <param name="itemToReplace">Query item to modify</param> /// <param name="replaceWith">String to apply in the query item data, in place of the matching string</param> public void Replace(IQueryMatch itemToReplace, object replaceWith) { string value = itemToReplace.GetValue().ToString(); itemToReplace.SetValue(Regex.Replace(value, m_pattern, replaceWith.ToString(), RegexOptions.IgnoreCase)); }
/// <summary> /// Tests whether the specified query item matches the string replacement pattern</summary> /// <param name="itemToMatch">Query item to test</param> /// <returns>True iff there was a match</returns> public bool Matches(IQueryMatch itemToMatch) { string value = itemToMatch.GetValue().ToString(); return Regex.Match(value, m_pattern, RegexOptions.IgnoreCase).Success; }
/// <summary> /// Tests whether the specified query item matches the numerical replacement pattern</summary> /// <param name="itemToMatch">Query item to test</param> /// <returns>True iff match successful</returns> public bool Matches(IQueryMatch itemToMatch) { return(IsConvertibleToDouble(itemToMatch.GetValue())); }
/// <summary> /// Tests whether the specified query item matches the string replacement pattern</summary> /// <param name="itemToMatch">Query item to test</param> /// <returns>True iff there was a match</returns> public bool Matches(IQueryMatch itemToMatch) { string value = itemToMatch.GetValue().ToString(); return(Regex.Match(value, m_pattern, RegexOptions.IgnoreCase).Success); }