mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-08 20:38:24 +02:00
28 lines
968 B
C#
28 lines
968 B
C#
using System;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace MediaBrowser.Common.Json.Converters
|
|
{
|
|
/// <summary>
|
|
/// Json Pipe delimited array converter factory.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This must be applied as an attribute, adding to the JsonConverter list causes stack overflow.
|
|
/// </remarks>
|
|
public class JsonPipeDelimitedArrayConverterFactory : JsonConverterFactory
|
|
{
|
|
/// <inheritdoc />
|
|
public override bool CanConvert(Type typeToConvert)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
|
|
return (JsonConverter)Activator.CreateInstance(typeof(JsonPipeDelimitedArrayConverter<>).MakeGenericType(structType));
|
|
}
|
|
}
|
|
}
|