Skip to content

Instantly share code, notes, and snippets.

@emoacht
Created June 18, 2025 14:55
Show Gist options
  • Save emoacht/e6b54a1d1db71b484db653477670bccc to your computer and use it in GitHub Desktop.
Save emoacht/e6b54a1d1db71b484db653477670bccc to your computer and use it in GitHub Desktop.
Converts pascal camel case enum value to upper hyphenated string.
using System;
using System.Text;
internal static class EnumHelper
{
public static string ToUpperHyphenated(Enum value)
{
var a = value.ToString();
var b = new StringBuilder();
for (int i = 0; i < a.Length; i++)
{
if (i > 0)
{
if (char.IsUpper(a[i]) ||
(char.IsDigit(a[i]) && !char.IsDigit(a[i - 1])))
{
b.Append('-');
}
}
b.Append(char.ToUpper(a[i]));
}
return b.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment