From d95396624878cde0122c1de94c18bea8dac7c30f Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 16 Apr 2014 17:01:26 +1000 Subject: [PATCH] Completes: U4-4670 Add .ContainsAny string extension to Umbraco.Core.StringExtensions --- src/Umbraco.Core/Dynamics/ExtensionMethods.cs | 28 +++---------------- src/Umbraco.Core/StringExtensions.cs | 10 +++++++ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Core/Dynamics/ExtensionMethods.cs b/src/Umbraco.Core/Dynamics/ExtensionMethods.cs index 0637864ceb..8439278b2e 100644 --- a/src/Umbraco.Core/Dynamics/ExtensionMethods.cs +++ b/src/Umbraco.Core/Dynamics/ExtensionMethods.cs @@ -36,42 +36,22 @@ namespace Umbraco.Core.Dynamics [Obsolete("This method should not be used and will be removed in the future")] public static bool ContainsAny(this string haystack, IEnumerable needles) { - if (haystack == null) throw new ArgumentNullException("haystack"); - if (!string.IsNullOrEmpty(haystack) || needles.Any()) - { - return needles.Any(haystack.Contains); - } - return false; + return StringExtensions.ContainsAny(haystack, needles); } [Obsolete("This method should not be used and will be removed in the future")] public static bool ContainsAny(this string haystack, params string[] needles) { - if (haystack == null) throw new ArgumentNullException("haystack"); - if (!string.IsNullOrEmpty(haystack) || needles.Length > 0) - { - return needles.Any(haystack.Contains); - } - return false; + return StringExtensions.ContainsAny(haystack, needles); } [Obsolete("This method should not be used and will be removed in the future")] public static bool ContainsAny(this string haystack, StringComparison comparison, IEnumerable needles) { - if (haystack == null) throw new ArgumentNullException("haystack"); - if (!string.IsNullOrEmpty(haystack) || needles.Any()) - { - return needles.Any(value => haystack.IndexOf(value, comparison) >= 0); - } - return false; + return StringExtensions.ContainsAny(haystack, needles, comparison); } [Obsolete("This method should not be used and will be removed in the future")] public static bool ContainsAny(this string haystack, StringComparison comparison, params string[] needles) { - if (haystack == null) throw new ArgumentNullException("haystack"); - if (!string.IsNullOrEmpty(haystack) || needles.Length > 0) - { - return needles.Any(value => haystack.IndexOf(value, comparison) >= 0); - } - return false; + return StringExtensions.ContainsAny(haystack, needles, comparison); } [Obsolete("This method should not be used and will be removed in the future")] public static bool ContainsInsensitive(this string haystack, string needle) diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index ac5e8b0ec6..5864b9d159 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -1180,5 +1180,15 @@ namespace Umbraco.Core */ } + public static bool ContainsAny(this string haystack, IEnumerable needles, StringComparison comparison = StringComparison.CurrentCulture) + { + if (haystack == null) throw new ArgumentNullException("haystack"); + if (string.IsNullOrEmpty(haystack) == false || needles.Any()) + { + return needles.Any(value => haystack.IndexOf(value) >= 0); + } + return false; + } + } }