aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Extensions/EnumerableExtensions.cs
diff options
context:
space:
mode:
authorClaus Vium <cvium@users.noreply.github.com>2021-06-22 07:38:08 +0200
committerGitHub <noreply@github.com>2021-06-22 07:38:08 +0200
commitf50bdb0f328e0c853f97521b12c3618b1af55e0b (patch)
treeec7eb27175c1a00a2f6199a012d69c152a082c3c /src/Jellyfin.Extensions/EnumerableExtensions.cs
parent026d8d28b7e7e0aea54426eff05419e2bfc735a0 (diff)
parentdb716bde95e6c14afc48d1343fc74ddbbd2ad97e (diff)
Merge pull request #6204 from Bond-009/extensions
Diffstat (limited to 'src/Jellyfin.Extensions/EnumerableExtensions.cs')
-rw-r--r--src/Jellyfin.Extensions/EnumerableExtensions.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Jellyfin.Extensions/EnumerableExtensions.cs b/src/Jellyfin.Extensions/EnumerableExtensions.cs
new file mode 100644
index 0000000000..b5fe933571
--- /dev/null
+++ b/src/Jellyfin.Extensions/EnumerableExtensions.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+
+namespace Jellyfin.Extensions
+{
+ /// <summary>
+ /// Static extensions for the <see cref="IEnumerable{T}"/> interface.
+ /// </summary>
+ public static class EnumerableExtensions
+ {
+ /// <summary>
+ /// Determines whether the value is contained in the source collection.
+ /// </summary>
+ /// <param name="source">An instance of the <see cref="IEnumerable{String}"/> interface.</param>
+ /// <param name="value">The value to look for in the collection.</param>
+ /// <param name="stringComparison">The string comparison.</param>
+ /// <returns>A value indicating whether the value is contained in the collection.</returns>
+ /// <exception cref="ArgumentNullException">The source is null.</exception>
+ public static bool Contains(this IEnumerable<string> source, ReadOnlySpan<char> value, StringComparison stringComparison)
+ {
+ if (source == null)
+ {
+ throw new ArgumentNullException(nameof(source));
+ }
+
+ if (source is IList<string> list)
+ {
+ int len = list.Count;
+ for (int i = 0; i < len; i++)
+ {
+ if (value.Equals(list[i], stringComparison))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ foreach (string element in source)
+ {
+ if (value.Equals(element, stringComparison))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+}