diff options
| author | Negulici-R. Barnabas <109497789+negulici-r-barnabas@users.noreply.github.com> | 2022-11-13 15:29:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-13 15:29:16 +0200 |
| commit | b7aa5ed862db11bbbc0a4ea5c92a67b772bfc35d (patch) | |
| tree | d8f396f581f3bdbd4be4c34d4a949df9fff72934 /src/Jellyfin.Extensions/EnumerableExtensions.cs | |
| parent | 1e41636e30b82518633ac6979564ff98bb40aca9 (diff) | |
| parent | 6655cf4e58285f51b612efb0bb6229f036da2591 (diff) | |
Merge branch 'jellyfin:master' into master
Diffstat (limited to 'src/Jellyfin.Extensions/EnumerableExtensions.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/EnumerableExtensions.cs | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/src/Jellyfin.Extensions/EnumerableExtensions.cs b/src/Jellyfin.Extensions/EnumerableExtensions.cs index b5fe93357..fd46358a4 100644 --- a/src/Jellyfin.Extensions/EnumerableExtensions.cs +++ b/src/Jellyfin.Extensions/EnumerableExtensions.cs @@ -1,45 +1,31 @@ using System; using System.Collections.Generic; -namespace Jellyfin.Extensions +namespace Jellyfin.Extensions; + +/// <summary> +/// Static extensions for the <see cref="IEnumerable{T}"/> interface. +/// </summary> +public static class EnumerableExtensions { /// <summary> - /// Static extensions for the <see cref="IEnumerable{T}"/> interface. + /// Determines whether the value is contained in the source collection. /// </summary> - public static class EnumerableExtensions + /// <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) { - /// <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)); - } + ArgumentNullException.ThrowIfNull(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 (source is IList<string> list) + { + int len = list.Count; + for (int i = 0; i < len; i++) { - if (value.Equals(element, stringComparison)) + if (value.Equals(list[i], stringComparison)) { return true; } @@ -47,5 +33,26 @@ namespace Jellyfin.Extensions return false; } + + foreach (string element in source) + { + if (value.Equals(element, stringComparison)) + { + return true; + } + } + + return false; + } + + /// <summary> + /// Gets an IEnumerable from a single item. + /// </summary> + /// <param name="item">The item to return.</param> + /// <typeparam name="T">The type of item.</typeparam> + /// <returns>The IEnumerable{T}.</returns> + public static IEnumerable<T> SingleItemAsEnumerable<T>(this T item) + { + yield return item; } } |
