/// <summary> /// Returns true if a string contains a substring, using the specified StringComparison. /// </summary> public static bool Contains(this string s, string value, StringComparison sc) { CompareOptions co; switch (sc) { case StringComparison.CurrentCulture: co = CompareOptions.None; break; case StringComparison.CurrentCultureIgnoreCase: co = CompareOptions.IgnoreCase; break; case StringComparison.InvariantCulture: co = CompareOptions.None; break; case StringComparison.InvariantCultureIgnoreCase: co = CompareOptions.IgnoreCase; break; case StringComparison.Ordinal: co = CompareOptions.Ordinal; break; case StringComparison.OrdinalIgnoreCase: co = CompareOptions.OrdinalIgnoreCase; break; default: throw new InvalidOperationException("Unknown string comparison value."); } return(s.Contains(value, sc.RelatedCulture(), co)); }