Created
December 12, 2023 13:21
-
-
Save Volorf/4ed48e0ba6dd697b58da585ade8193ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ExtensionMethods | |
{ | |
public static class MyExtensions | |
{ | |
public static void Next(this ref MyEnum item) | |
{ | |
int count = Enum.GetNames(typeof(MyEnum)).Length; | |
int index = item.GetHashCode(); | |
int nextIndex = index + 1; | |
if (nextIndex >= count) nextIndex = 0; | |
item = (MyEnum) nextIndex; | |
} | |
public static void Previous(this ref MyEnum item) | |
{ | |
int count = Enum.GetNames(typeof(MyEnum)).Length; | |
int index = item.GetHashCode(); | |
int prevIndex = index - 1; | |
if (prevIndex <= 0) prevIndex = count - 1; | |
item = (MyEnum) prevIndex; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment