diff --git a/src/Spectre.Console/Internal/DecorationTable.cs b/src/Spectre.Console/Internal/DecorationTable.cs index 9871e29..da5c108 100644 --- a/src/Spectre.Console/Internal/DecorationTable.cs +++ b/src/Spectre.Console/Internal/DecorationTable.cs @@ -54,8 +54,7 @@ internal static class DecorationTable { var result = new List(); - Enum.GetValues(typeof(Decoration)) - .Cast() + EnumUtils.GetValues() .Where(flag => (decoration & flag) != 0) .ForEach(flag => { diff --git a/src/Spectre.Console/Internal/FileSize.cs b/src/Spectre.Console/Internal/FileSize.cs index b47a612..46d22d8 100644 --- a/src/Spectre.Console/Internal/FileSize.cs +++ b/src/Spectre.Console/Internal/FileSize.cs @@ -140,7 +140,7 @@ internal struct FileSize bytes *= 8; } - foreach (var prefix in (FileSizePrefix[])Enum.GetValues(typeof(FileSizePrefix))) + foreach (var prefix in EnumUtils.GetValues()) { // Trying to find the largest unit, that the number of bytes can fit under. Ex. 40kb < 1mb if (bytes < Math.Pow((int)_prefixBase, (int)prefix + 1)) diff --git a/src/Spectre.Console/Internal/Polyfill/EnumHelpers.cs b/src/Spectre.Console/Internal/Polyfill/EnumHelpers.cs new file mode 100644 index 0000000..b1db26b --- /dev/null +++ b/src/Spectre.Console/Internal/Polyfill/EnumHelpers.cs @@ -0,0 +1,15 @@ +namespace Spectre.Console; + +internal static class EnumUtils +{ + public static T[] GetValues() + where T : struct, Enum + { + return +#if NET6_0_OR_GREATER + Enum.GetValues(); +#else + (T[])Enum.GetValues(typeof(T)); +#endif + } +} \ No newline at end of file