diff options
| author | Claus Vium <cvium@users.noreply.github.com> | 2021-03-08 21:23:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-08 21:23:14 +0100 |
| commit | 90cdd1345dde15f987550c57c12fcd8e57af0de1 (patch) | |
| tree | fdd25759a5174721c16b840895bb55f3c086f31c /MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs | |
| parent | 480dd66428e2a8bf76c0747256f2e99b15aae212 (diff) | |
| parent | 54f81c4da484e3bb3d62669f0216c2a3a239166d (diff) | |
Merge pull request #5407 from Bond-009/hack
Diffstat (limited to 'MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs')
| -rw-r--r-- | MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs b/MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs new file mode 100644 index 000000000..7c627f0e3 --- /dev/null +++ b/MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs @@ -0,0 +1,29 @@ +#nullable disable +// THIS IS A HACK +// TODO: @bond Move to separate project + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MediaBrowser.Model.Entities +{ + /// <summary> + /// Converts an object to a lowercase string. + /// </summary> + /// <typeparam name="T">The object type.</typeparam> + public class JsonLowerCaseConverter<T> : JsonConverter<T> + { + /// <inheritdoc /> + public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return JsonSerializer.Deserialize<T>(ref reader, options); + } + + /// <inheritdoc /> + public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + { + writer.WriteStringValue(value?.ToString().ToLowerInvariant()); + } + } +} |
