aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs
diff options
context:
space:
mode:
authorGreenback <jimcartlidge@yahoo.co.uk>2020-10-09 14:12:41 +0100
committerGreenback <jimcartlidge@yahoo.co.uk>2020-10-09 14:12:41 +0100
commitebe650afa9e622d3f9e53e50b42ea676fdc25e6e (patch)
tree51da5ba142a8243b0d36313ec0e54318132ff3a2 /MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs
parent8a4f81c9a7a03c6a45a8a9331f71ba06ae0ce521 (diff)
parent10d48b062315581adc4706530bc388d53ff232a4 (diff)
Merge remote-tracking branch 'upstream/master' into NetworkPR2
Diffstat (limited to 'MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs')
-rw-r--r--MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs b/MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs
new file mode 100644
index 000000000..d5b54e3ca
--- /dev/null
+++ b/MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace MediaBrowser.Common.Json.Converters
+{
+ /// <summary>
+ /// Json nullable struct converter factory.
+ /// </summary>
+ public class JsonNullableStructConverterFactory : JsonConverterFactory
+ {
+ /// <inheritdoc />
+ public override bool CanConvert(Type typeToConvert)
+ {
+ return typeToConvert.IsGenericType
+ && typeToConvert.GetGenericTypeDefinition() == typeof(Nullable<>)
+ && typeToConvert.GenericTypeArguments[0].IsValueType;
+ }
+
+ /// <inheritdoc />
+ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
+ {
+ var structType = typeToConvert.GenericTypeArguments[0];
+ return (JsonConverter)Activator.CreateInstance(typeof(JsonNullableStructConverter<>).MakeGenericType(structType));
+ }
+ }
+} \ No newline at end of file