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.
44 lines
1.2 KiB
44 lines
1.2 KiB
using System.Globalization; |
|
using System.Text; |
|
using Newtonsoft.Json.Serialization; |
|
|
|
namespace ErsatzTV.Infrastructure.Trakt; |
|
|
|
public class DeliminatorSeparatedPropertyNamesContractResolver : DefaultContractResolver |
|
{ |
|
private readonly string _separator; |
|
|
|
protected DeliminatorSeparatedPropertyNamesContractResolver(char separator) => |
|
_separator = separator.ToString(CultureInfo.InvariantCulture); |
|
|
|
protected override string ResolvePropertyName(string propertyName) |
|
{ |
|
var parts = new List<string>(); |
|
var currentWord = new StringBuilder(); |
|
|
|
foreach (char c in propertyName) |
|
{ |
|
if (char.IsUpper(c) && currentWord.Length > 0) |
|
{ |
|
parts.Add(currentWord.ToString()); |
|
currentWord.Clear(); |
|
} |
|
|
|
currentWord.Append(char.ToLower(c, CultureInfo.InvariantCulture)); |
|
} |
|
|
|
if (currentWord.Length > 0) |
|
{ |
|
parts.Add(currentWord.ToString()); |
|
} |
|
|
|
return string.Join(_separator, parts.ToArray()); |
|
} |
|
} |
|
|
|
public class SnakeCasePropertyNamesContractResolver : DeliminatorSeparatedPropertyNamesContractResolver |
|
{ |
|
public SnakeCasePropertyNamesContractResolver() : base('_') |
|
{ |
|
} |
|
}
|
|
|