2020-10-12 03:09:15 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2020-10-29 17:32:02 +00:00
|
|
|
|
var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
|
2020-10-12 03:09:15 +00:00
|
|
|
|
return (JsonConverter)Activator.CreateInstance(typeof(JsonCommaDelimitedArrayConverter<>).MakeGenericType(structType));
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-29 17:32:02 +00:00
|
|
|
|
}
|