< Summary - Jellyfin

Information
Class: Jellyfin.Extensions.EnumerableExtensions
Assembly: Jellyfin.Extensions
File(s): /srv/git/jellyfin/src/Jellyfin.Extensions/EnumerableExtensions.cs
Line coverage
58%
Covered lines: 7
Uncovered lines: 5
Coverable lines: 12
Total lines: 58
Line coverage: 58.3%
Branch coverage
50%
Covered branches: 5
Total branches: 10
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Contains(...)50%17.241058.33%

File(s)

/srv/git/jellyfin/src/Jellyfin.Extensions/EnumerableExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace Jellyfin.Extensions;
 5
 6/// <summary>
 7/// Static extensions for the <see cref="IEnumerable{T}"/> interface.
 8/// </summary>
 9public static class EnumerableExtensions
 10{
 11    /// <summary>
 12    /// Determines whether the value is contained in the source collection.
 13    /// </summary>
 14    /// <param name="source">An instance of the <see cref="IEnumerable{String}"/> interface.</param>
 15    /// <param name="value">The value to look for in the collection.</param>
 16    /// <param name="stringComparison">The string comparison.</param>
 17    /// <returns>A value indicating whether the value is contained in the collection.</returns>
 18    /// <exception cref="ArgumentNullException">The source is null.</exception>
 19    public static bool Contains(this IEnumerable<string> source, ReadOnlySpan<char> value, StringComparison stringCompar
 20    {
 1310021        ArgumentNullException.ThrowIfNull(source);
 22
 1310023        if (source is IList<string> list)
 24        {
 1310025            int len = list.Count;
 59865026            for (int i = 0; i < len; i++)
 27            {
 29557228                if (value.Equals(list[i], stringComparison))
 29                {
 934730                    return true;
 31                }
 32            }
 33
 375334            return false;
 35        }
 36
 037        foreach (string element in source)
 38        {
 039            if (value.Equals(element, stringComparison))
 40            {
 041                return true;
 42            }
 43        }
 44
 045        return false;
 046    }
 47
 48    /// <summary>
 49    /// Gets an IEnumerable from a single item.
 50    /// </summary>
 51    /// <param name="item">The item to return.</param>
 52    /// <typeparam name="T">The type of item.</typeparam>
 53    /// <returns>The IEnumerable{T}.</returns>
 54    public static IEnumerable<T> SingleItemAsEnumerable<T>(this T item)
 55    {
 56        yield return item;
 57    }
 58}