Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Created January 22, 2018 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phrohdoh/6797ce1cace846e73d2c4e9e14e7452a to your computer and use it in GitHub Desktop.
Save phrohdoh/6797ce1cace846e73d2c4e9e14e7452a to your computer and use it in GitHub Desktop.
Convert snake-case string to pascal-case and print as C# properties
function snake_to_pascal() {
# NOTE: Only use `gsed` if you are running macOS (install `gsed` via `brew install gnu-sed`),
# else change to `sed`.
echo "$1" | gsed 's/_\([a-z]\)/\U\1/g;s/^\([a-z]\)/\U\1/g' | xargs printf "[JsonProperty(\"$1\")]\npublic object %s { get; set; }\n"
}
snake_to_pascal 'id'
snake_to_pascal 'first_name'
snake_to_pascal 'last_name'
snake_to_pascal 'age'
# etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment