mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:45:42 +00:00
Use generic Enum.GetValues
This commit is contained in:
parent
3c60340bde
commit
5168948a1d
@ -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];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user