Thursday, September 19, 2013

C# Enum.ToString() with complete name

C# Enum.ToString() with complete name

I am searching a solution to get the complete String of an enum.
Example:
Public Enum Color
{
Red = 1,
Blue = 2
}
Color color = Color.Red;
// This will always get "Red" but I need "Color.Red"
string colorString = color.ToString();
// I know that this is what I need:
colorString = Color.Red.ToString();
So is there a solution?

1 comment:

  1. public static class Extensions
    {
    public static string GetFullName(this Enum myEnum)
    {
    return string.Format("{0}.{1}", myEnum.GetType().Name, myEnum.ToString());
    }
    }
    Color color = Color.Red;
    string fullName = color.GetFullName();
    SAML for .NET

    ReplyDelete