Created
January 22, 2018 20:30
-
-
Save phrohdoh/6797ce1cace846e73d2c4e9e14e7452a to your computer and use it in GitHub Desktop.
Convert snake-case string to pascal-case and print as C# properties
This file contains 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
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