Merge pull request #15774 from stevenaw/optimize-GetUniqueFlags

Optimize GetUniqueFlags<T>()
This commit is contained in:
Bond-009 2025-12-12 18:00:25 +01:00 committed by GitHub
commit baa8d40940
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

@ -64,13 +64,13 @@ public static class EnumerableExtensions
/// <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
where T : struct, Enum
{
foreach (Enum value in Enum.GetValues(flags.GetType()))
foreach (T value in Enum.GetValues<T>())
{
if (flags.HasFlag(value))
{
yield return (T)value;
yield return value;
}
}
}