Skip to content

Instantly share code, notes, and snippets.

@FaronBracy
Created August 26, 2014 12:29
Show Gist options
  • Save FaronBracy/f295950ce4416cdf0ef1 to your computer and use it in GitHub Desktop.
Save FaronBracy/f295950ce4416cdf0ef1 to your computer and use it in GitHub Desktop.
Jon Skeet's Clever Enum
public class MyCleverEnum
{
public static readonly MyCleverEnum First = new FirstCleverEnum();
public static readonly MyCleverEnum Second = new SecondCleverEnum();
// Can only be called by this type *and nested types*
private MyCleverEnum()
{
}
public abstract void SomeMethod();
public abstract void AnotherMethod();
private class FirstCleverEnum : MyCleverEnum
{
public override void SomeMethod()
{
// First-specific behaviour here
}
public override void AnotherMethod()
{
// First-specific behaviour here
}
}
private class SecondCleverEnum : MyCleverEnum
{
public override void SomeMethod()
{
// Second-specific behaviour here
}
public override void AnotherMethod()
{
// Second-specific behaviour here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment