mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Globalization; |
|
using System.Text; |
|
using Newtonsoft.Json.Serialization; |
|
|
|
namespace ErsatzTV.Infrastructure.Trakt |
|
{ |
|
public class DeliminatorSeparatedPropertyNamesContractResolver : DefaultContractResolver |
|
{ |
|
readonly string separator; |
|
|
|
protected DeliminatorSeparatedPropertyNamesContractResolver(char separator) |
|
{ |
|
this.separator = separator.ToString(CultureInfo.InvariantCulture); |
|
} |
|
|
|
protected override string ResolvePropertyName(string propertyName) |
|
{ |
|
var parts = new List<string>(); |
|
var currentWord = new StringBuilder(); |
|
|
|
foreach (var c in propertyName.ToCharArray()) |
|
{ |
|
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()); |
|
} |
|
} |
|
|
|
public class SnakeCasePropertyNamesContractResolver : DeliminatorSeparatedPropertyNamesContractResolver |
|
{ |
|
public SnakeCasePropertyNamesContractResolver() : base('_') { } |
|
} |
|
}
|
|
|