* better trakt list support * update dependencies * revert unneeded brackets
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
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('_') { }
|
|
}
|
|
}
|