using System;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.ModelBinders
{
///
/// Nullable enum model binder provider.
///
public class NullableEnumModelBinderProvider : IModelBinderProvider
{
///
public IModelBinder? GetBinder(ModelBinderProviderContext context)
{
var nullableType = Nullable.GetUnderlyingType(context.Metadata.ModelType);
if (nullableType is null || !nullableType.IsEnum)
{
// Type isn't nullable or isn't an enum.
return null;
}
var logger = context.Services.GetRequiredService>();
return new NullableEnumModelBinder(logger);
}
}
}