how can i use switch statement on type-safe enum pattern
        Posted  
        
            by 
                Fer
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Fer
        
        
        
        Published on 2012-04-11T05:32:34Z
        Indexed on 
            2012/04/11
            17:29 UTC
        
        
        Read the original article
        Hit count: 323
        
I found a goodlooking example about implementation enums in a different way. That is called type-safe enum pattern i think. I started using it but i realized that i can not use it in a switch statement. 
My implementation looks like the following:
public sealed class MyState
{
    private readonly string m_Name;
    private readonly int m_Value;
    public static readonly MyState PASSED= new MyState(1, "OK");
    public static readonly MyState FAILED= new MyState(2, "ERROR");
    private MyState(int value, string name)
    {
        m_Name = name;
        m_Value = value;
    }
    public override string ToString()
    {
        return m_Name;
    }
    public int GetIntValue()
    {
        return m_Value;
    }
}
What can i add to my class in order to be able to use this pattern in switch statements in C#?
Thanks.
© Stack Overflow or respective owner