/// <summary> /// searches for text within a string (is or contains). Not an instance method (per se), /// but private. /// </summary> /// <param name="isOrContains"></param> /// <param name="searchFor"></param> /// <param name="text"></param> /// <returns></returns> private static bool Matches(SearchTypeIsContains isOrContains, string searchFor, string text, bool ignoreCase) { text = text.ToLower(); searchFor = searchFor.ToLower(); if (isOrContains == SearchTypeIsContains.Contains) { int where = text.IndexOf(searchFor); if (where != -1) return true; } else { if (text.Equals(searchFor)) return true; } return false; }
/// <summary> /// searches for date within a string (is or contains). Not really an instance method. /// </summary> /// <param name="isOrContains"></param> /// <param name="searchFor"></param> /// <param name="text"></param> /// <returns></returns> private static bool Matches(SearchTypeIsContains isOrContains, string searchFor, DateTime snippetVal) { // pull off the time DateTime searchForDate = DateTime.Parse(searchFor).Date; snippetVal = snippetVal.Date; // get just the date part int beforeOnAfter = snippetVal.CompareTo(searchForDate); if (isOrContains == SearchTypeIsContains.Before) { if (beforeOnAfter == -1) return true; } else if (isOrContains == SearchTypeIsContains.After) { if (beforeOnAfter == 1) return true; } if (beforeOnAfter == 0) return true; // jackpot, the values are equal, it hits all three conditions, // before after and IS return false; }