1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:18:47 +00:00

Use generic Enum.GetValues

This commit is contained in:
Oliver Booth 2022-04-20 14:09:13 +01:00
parent 3c60340bde
commit 5168948a1d
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634

View File

@ -21,7 +21,7 @@ public static class EnumExtensions
public static T Next<T>(this T source, bool wrap = true)
where T : struct, Enum
{
var array = (T[])Enum.GetValues(source.GetType());
var array = Enum.GetValues<T>();
int index = Array.IndexOf(array, source) + 1;
return array.Length == index ? array[wrap ? 0 : index - 1] : array[index];
}
@ -42,7 +42,7 @@ public static class EnumExtensions
public static T Previous<T>(this T source, bool wrap = true)
where T : struct, Enum
{
var array = (T[])Enum.GetValues(source.GetType());
var array = Enum.GetValues<T>();
int index = Array.IndexOf(array, source) - 1;
return index < 0 ? array[wrap ? array.Length - 1 : 0] : array[index];
}