using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Converters;
namespace StardewModdingAPI.Framework.Serialisation
{
/// A variant of which only converts certain enums.
internal class SelectiveStringEnumConverter : StringEnumConverter
{
/*********
** Properties
*********/
/// The enum type names to convert.
private readonly HashSet Types;
/*********
** Public methods
*********/
/// Construct an instance.
/// The enum types to convert.
public SelectiveStringEnumConverter(params Type[] types)
{
this.Types = new HashSet(types.Select(p => p.FullName));
}
/// Get whether this instance can convert the specified object type.
/// The object type.
public override bool CanConvert(Type type)
{
return
base.CanConvert(type)
&& this.Types.Contains((Nullable.GetUnderlyingType(type) ?? type).FullName);
}
}
}