diff options
| author | crobibero <cody@robibe.ro> | 2020-09-03 08:06:40 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-09-03 08:06:40 -0600 |
| commit | bebb0afb528636659bfb4d635acf77c4e83daa55 (patch) | |
| tree | 273f087464d28a7b3fa8877477a809ee42d63ebe /MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs | |
| parent | 1d9285c59443692008514aea0a3a30ff11b468de (diff) | |
| parent | 3711a1978e8a400aa28dd75ce8ffb08ac43106e1 (diff) | |
Merge remote-tracking branch 'upstream/master' into api-doc-css
Diffstat (limited to 'MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs')
| -rw-r--r-- | MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs b/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs deleted file mode 100644 index 52f360740..000000000 --- a/MediaBrowser.Common/Json/Converters/JsonNonStringKeyDictionaryConverterFactory.cs +++ /dev/null @@ -1,59 +0,0 @@ -#nullable enable - -using System; -using System.Collections; -using System.Globalization; -using System.Reflection; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace MediaBrowser.Common.Json.Converters -{ - /// <summary> - /// https://github.com/dotnet/runtime/issues/30524#issuecomment-524619972. - /// TODO This can be removed when System.Text.Json supports Dictionaries with non-string keys. - /// </summary> - internal sealed class JsonNonStringKeyDictionaryConverterFactory : JsonConverterFactory - { - /// <summary> - /// Only convert objects that implement IDictionary and do not have string keys. - /// </summary> - /// <param name="typeToConvert">Type convert.</param> - /// <returns>Conversion ability.</returns> - public override bool CanConvert(Type typeToConvert) - { - if (!typeToConvert.IsGenericType) - { - return false; - } - - // Let built in converter handle string keys - if (typeToConvert.GenericTypeArguments[0] == typeof(string)) - { - return false; - } - - // Only support objects that implement IDictionary - return typeToConvert.GetInterface(nameof(IDictionary)) != null; - } - - /// <summary> - /// Create converter for generic dictionary type. - /// </summary> - /// <param name="typeToConvert">Type to convert.</param> - /// <param name="options">Json serializer options.</param> - /// <returns>JsonConverter for given type.</returns> - public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) - { - var converterType = typeof(JsonNonStringKeyDictionaryConverter<,>) - .MakeGenericType(typeToConvert.GenericTypeArguments[0], typeToConvert.GenericTypeArguments[1]); - var converter = (JsonConverter)Activator.CreateInstance( - converterType, - BindingFlags.Instance | BindingFlags.Public, - null, - null, - CultureInfo.CurrentCulture); - return converter; - } - } -} |
