summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Serialisation/StringEnumConverter.cs
blob: 7afe86cdf69540ce30824f59c6bb82f6aa96d646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using Newtonsoft.Json.Converters;

namespace StardewModdingAPI.Framework.Serialisation
{
    /// <summary>A variant of <see cref="StringEnumConverter"/> which only converts a specified enum.</summary>
    /// <typeparam name="T">The enum type.</typeparam>
    internal class StringEnumConverter<T> : StringEnumConverter
    {
        /*********
        ** Public methods
        *********/
        /// <summary>Get whether this instance can convert the specified object type.</summary>
        /// <param name="type">The object type.</param>
        public override bool CanConvert(Type type)
        {
            return
                base.CanConvert(type)
                && (Nullable.GetUnderlyingType(type) ?? type) == typeof(T);
        }
    }
}