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?
public static class Extensions
{
    public static string GetFullName(this Enum myEnum)
    {
      return string.Format("{0}.{1}", myEnum.GetType().Name, myEnum.ToString());
    }
}
usage:
Color color = Color.Red;
string fullName = color.GetFullName();
Note: I think GetType().Name is better that GetType().FullName
Try this:
        Color color = Color.Red;
        string colorString = color.GetType().Name + "." + Enum.GetName(typeof(Color), color);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With