Skip to content

Instantly share code, notes, and snippets.

@amilos
Last active October 9, 2017 16:50
Show Gist options
  • Save amilos/4f7be27d10060b619561cd86bebbd67e to your computer and use it in GitHub Desktop.
Save amilos/4f7be27d10060b619561cd86bebbd67e to your computer and use it in GitHub Desktop.
Kebab case resolver extension for Newtonsoft.JSON library
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