diff options
| author | Bond_009 <bond.009@outlook.com> | 2020-01-09 18:26:22 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2020-01-09 18:26:22 +0100 |
| commit | b50c4938e19eaa4508dd9192bc63c3788c2fa3eb (patch) | |
| tree | e8a29d7c1ecc22b20287a940d757d635b5208b00 /MediaBrowser.Common/Json/Converters/JsonGuidConverter.cs | |
| parent | a1ca50fd5a74eafa6e609976d90cad42b54137e5 (diff) | |
| parent | 162c1ac7b7fde0e4929cf262b0f275e3eb15524c (diff) | |
Merge branch 'master' into namingtests
Diffstat (limited to 'MediaBrowser.Common/Json/Converters/JsonGuidConverter.cs')
| -rw-r--r-- | MediaBrowser.Common/Json/Converters/JsonGuidConverter.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonGuidConverter.cs b/MediaBrowser.Common/Json/Converters/JsonGuidConverter.cs new file mode 100644 index 000000000..d35a761f3 --- /dev/null +++ b/MediaBrowser.Common/Json/Converters/JsonGuidConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MediaBrowser.Common.Json.Converters +{ + /// <summary> + /// Converts a GUID object or value to/from JSON. + /// </summary> + public class JsonGuidConverter : JsonConverter<Guid> + { + /// <inheritdoc /> + public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + => new Guid(reader.GetString()); + + /// <inheritdoc /> + public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options) + => writer.WriteStringValue(value); + } +} |
