mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-11 12:46:20 +00:00
Reduce allocations, simplifed code, faster implementation, included tests - StreamInfo.ToUrl (#9369)
* Rework PR 6168 * Fix test
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Jellyfin.Extensions;
|
||||
|
||||
@@ -55,4 +56,22 @@ public static class EnumerableExtensions
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an IEnumerable consisting of all flags of an enum.
|
||||
/// </summary>
|
||||
/// <param name="flags">The flags enum.</param>
|
||||
/// <typeparam name="T">The type of item.</typeparam>
|
||||
/// <returns>The IEnumerable{Enum}.</returns>
|
||||
public static IEnumerable<T> GetUniqueFlags<T>(this T flags)
|
||||
where T : Enum
|
||||
{
|
||||
foreach (Enum value in Enum.GetValues(flags.GetType()))
|
||||
{
|
||||
if (flags.HasFlag(value))
|
||||
{
|
||||
yield return (T)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user