-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom naming convention for JsonNamingPolicy for snake_case
- Loading branch information
1 parent
ef1ac6e
commit 3a3ec79
Showing
3 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
provider_azure_function/Utilities/SnakeCaseNamingPolicy.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json; | ||
|
||
public class SnakeCaseNamingPolicy : JsonNamingPolicy | ||
{ | ||
public static SnakeCaseNamingPolicy Instance { get; } = new SnakeCaseNamingPolicy(); | ||
|
||
public override string ConvertName(string name) | ||
{ | ||
// Conversion to other naming convention goes here. Like SnakeCase, KebabCase etc. | ||
return name.ToSnakeCase(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public static class StringUtils | ||
{ | ||
public static string ToSnakeCase(this string str) | ||
{ | ||
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToLower(); | ||
} | ||
} |