Forked from roryf/DeliminatorSeparatedPropertyNamesContractResolver.cs
Created
February 11, 2014 13:16
-
-
Save mahizsas/8934628 to your computer and use it in GitHub Desktop.
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
public class DeliminatorSeparatedPropertyNamesContractResolver : DefaultContractResolver | |
{ | |
private readonly string _separator; | |
protected DeliminatorSeparatedPropertyNamesContractResolver(char separator) : base(true) | |
{ | |
_separator = separator.ToString(); | |
} | |
protected override string ResolvePropertyName(string propertyName) | |
{ | |
var parts = new List<string>(); | |
var currentWord = new StringBuilder(); | |
foreach (var c in propertyName) | |
{ | |
if (char.IsUpper(c) && currentWord.Length > 0) | |
{ | |
parts.Add(currentWord.ToString()); | |
currentWord.Clear(); | |
} | |
currentWord.Append(char.ToLower(c)); | |
} | |
if (currentWord.Length > 0) | |
{ | |
parts.Add(currentWord.ToString()); | |
} | |
return string.Join(_separator, parts.ToArray()); | |
} | |
} |
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
public class SnakeCasePropertyNamesContractResolver : DeliminatorSeparatedPropertyNamesContractResolver | |
{ | |
public SnakeCasePropertyNamesContractResolver() : base('_') { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment