diff options
| author | Bond-009 <bond.009@outlook.com> | 2020-10-27 19:36:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-27 19:36:37 +0100 |
| commit | be2f27a0695e5f3102f79a2e246e971682cff603 (patch) | |
| tree | 8179a36a3a734666d4a5d9a147d999f821ec79c9 /MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs | |
| parent | 6cadbe8d9eb28230fd9476f318309cb95443fa59 (diff) | |
| parent | b2662894cf6e7e6b20d12ff22c79ee5159658a2a (diff) | |
Merge pull request #4312 from crobibero/json-array-converter
Add comma delimited string to array json converter
Diffstat (limited to 'MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs')
| -rw-r--r-- | MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs b/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs new file mode 100644 index 000000000..b7b1daf76 --- /dev/null +++ b/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs @@ -0,0 +1,28 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MediaBrowser.Common.Json.Converters +{ + /// <summary> + /// Json comma delimited array converter factory. + /// </summary> + /// <remarks> + /// This must be applied as an attribute, adding to the JsonConverter list causes stack overflow. + /// </remarks> + public class JsonCommaDelimitedArrayConverterFactory : JsonConverterFactory + { + /// <inheritdoc /> + public override bool CanConvert(Type typeToConvert) + { + return true; + } + + /// <inheritdoc /> + public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) + { + var structType = typeToConvert.GetElementType(); + return (JsonConverter)Activator.CreateInstance(typeof(JsonCommaDelimitedArrayConverter<>).MakeGenericType(structType)); + } + } +}
\ No newline at end of file |
