You have to take the attribute that has the text you want. You can use this:
public static class EnumExt {
public static string GetAttributeDescription(this Enum enumValue) {
var attributes = enumValue.GetType().GetMember(enumValue.ToString())[0].GetCustomAttributes(typeof(XmlEnumAttribute), false);
return (attributes.Length > 0) ? ((XmlEnumAttribute)attributes[0]).Name : String.Empty;
}
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
I would rethink some things. I don’t know if this is a case to use an enumeration. Enumerations cannot be subject to changes in legislation or actions that you have no control over. This will cause huge maintenance problems. I have experience with this and I can say that you will regret using it in place of a simple table (a dictionary or a specialized type. These data are inherently mutable.
The name already indicates that something is wrong. It has become so confused that it has little use. Even if it were an enumeration, the form used seems to be wrong. It seems to have enumerations within the enumeration name. The appeal seems to be quite wrong.
even if it were to adopt this solution would need to do in a way that this content is more meaningful and easy to organize and manipulate.
Maybe I already made the whole system thinking about it. Still I would reformulate everything. It is a serious conceptual error that will bring so many disorders that remaking is already the best solution.
Thank you. Solved.
– Robss70