using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MediaBrowser.Common.Json.Converters
{
///
/// Json Pipe delimited array converter factory.
///
///
/// This must be applied as an attribute, adding to the JsonConverter list causes stack overflow.
///
public class JsonPipeDelimitedArrayConverterFactory : JsonConverterFactory
{
///
public override bool CanConvert(Type typeToConvert)
{
return true;
}
///
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
return (JsonConverter)Activator.CreateInstance(typeof(JsonPipeDelimitedArrayConverter<>).MakeGenericType(structType));
}
}
}