Created
June 18, 2025 14:55
-
-
Save emoacht/e6b54a1d1db71b484db653477670bccc to your computer and use it in GitHub Desktop.
Converts pascal camel case enum value to upper hyphenated string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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