Last active
October 9, 2017 16:50
-
-
Save amilos/4f7be27d10060b619561cd86bebbd67e to your computer and use it in GitHub Desktop.
Kebab case resolver extension for Newtonsoft.JSON library
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
using Newtonsoft.Json.Serialization; | |
namespace Asseco.JsonUtils | |
{ | |
public class KebabCaseResolver : DefaultContractResolver | |
{ | |
private Regex regex = new Regex("(?<!^)((?<=[a-zA-Z0-9])[A-Z][a-z])|((?<=[a-z])[A-Z])", RegexOptions.Compiled); | |
protected override string ResolvePropertyName(string propertyName) | |
{ | |
return regex.Replace(propertyName, "-$1$2").ToLower(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment