diff options
| author | Tim Eisele <Ghost_of_Stone@web.de> | 2025-03-28 13:51:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-28 06:51:44 -0600 |
| commit | 9657708b384dfca474c28f673a2d79a3f3e4db9f (patch) | |
| tree | b9ebc35b8162ee6c6f96c6ae8f4d3c1a996b0a76 /src | |
| parent | cb931e00627559e4e9d14d2cc7d4ec8e00eb7061 (diff) | |
Reduce allocations, simplifed code, faster implementation, included tests - StreamInfo.ToUrl (#9369)
* Rework PR 6168
* Fix test
Diffstat (limited to 'src')
| -rw-r--r-- | src/Jellyfin.Extensions/EnumerableExtensions.cs | 19 |
1 files changed, 19 insertions, 0 deletions
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; } + + /// <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; + } + } + } } |
