Skip to content

Instantly share code, notes, and snippets.

@Volorf
Created December 12, 2023 13:21
Show Gist options
  • Save Volorf/4ed48e0ba6dd697b58da585ade8193ce to your computer and use it in GitHub Desktop.
Save Volorf/4ed48e0ba6dd697b58da585ade8193ce to your computer and use it in GitHub Desktop.
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