From 9657708b384dfca474c28f673a2d79a3f3e4db9f Mon Sep 17 00:00:00 2001 From: Tim Eisele Date: Fri, 28 Mar 2025 13:51:44 +0100 Subject: Reduce allocations, simplifed code, faster implementation, included tests - StreamInfo.ToUrl (#9369) * Rework PR 6168 * Fix test --- src/Jellyfin.Extensions/EnumerableExtensions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/Jellyfin.Extensions/EnumerableExtensions.cs b/src/Jellyfin.Extensions/EnumerableExtensions.cs index fd46358a4..3eb9da01f 100644 --- a/src/Jellyfin.Extensions/EnumerableExtensions.cs +++ b/src/Jellyfin.Extensions/EnumerableExtensions.cs @@ -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; } + + /// + /// Gets an IEnumerable consisting of all flags of an enum. + /// + /// The flags enum. + /// The type of item. + /// The IEnumerable{Enum}. + public static IEnumerable GetUniqueFlags(this T flags) + where T : Enum + { + foreach (Enum value in Enum.GetValues(flags.GetType())) + { + if (flags.HasFlag(value)) + { + yield return (T)value; + } + } + } } -- cgit v1.2.3