# Thursday, October 05, 2006
« Debugging 3rd party assemblies without b... | Main | IL overview »
Someone asked me today if there was a way to test the default statement in this piece of code:

public enum AEnum
{
    One,
    Two,
    Three
}

public void DoStuff(AEnum e)
{
    switch (e)
    {
        case AEnum.One:
            Console.WriteLine("AEnum.One");
            break;

        case AEnum.Two:
            Console.WriteLine("AEnum.Two");
            break;

        case AEnum.Three:
            Console.WriteLine("AEnum.Three");
            break;

        default:
            throw new Exception("Unhandled enumeration value");
            break;
    }
}

Unfortunately I don't see any way to do it without changing the design to something very wrong and ugly like:

public void DoStuff(Enum e)
{
    AEnum ae = (AEnum)e;

    switch (ae)
    {
        case AEnum.One:
            Console.WriteLine("AEnum.One");
            break;

        case AEnum.Two:
            Console.WriteLine("AEnum.Two");
            break;

        case AEnum.Three:
            Console.WriteLine("AEnum.Three");
            break;

        default:
           
throw new Exception("Unhandled enumeration value");
            break;
    }
}




Thursday, October 05, 2006 4:50:25 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
Comments are closed.