Enum Name To Display Name
Convert an CamelCase enum name to displayable string
Source
private static Regex UpperCamelCaseRegex = new Regex(@"(?<!^)((?<!\d)\d|(?(?<=[A-Z])[A-Z](?=[a-z])|[A-Z]))", RegexOptions.Compiled);
public static string AsUpperCamelCaseName(this Enum e)
{
return UpperCamelCaseRegex.Replace(e.ToString(), " $1");
}
Example
foreach(HttpStatusCode c in Enum.GetValues(typeof(HttpStatusCode)))
{
Console.WriteLine("Name:{0} - {1}", c, c.AsUpperCamelCaseName());
}