diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-01-20 21:29:47 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-01-20 21:29:47 -0500 |
commit | 894fd25a18cd5ddf31a905860aca95c438894efd (patch) | |
tree | 186d873b91e0b1bee2927aeef96b6513710af497 /src/SMAPI/Framework/Serialisation/Converters/StringEnumConverter.cs | |
parent | 9636d5b3aac99459e5933bc4fa6ddb8ca84917af (diff) | |
download | SMAPI-894fd25a18cd5ddf31a905860aca95c438894efd.tar.gz SMAPI-894fd25a18cd5ddf31a905860aca95c438894efd.tar.bz2 SMAPI-894fd25a18cd5ddf31a905860aca95c438894efd.zip |
move converters into namespace
Diffstat (limited to 'src/SMAPI/Framework/Serialisation/Converters/StringEnumConverter.cs')
-rw-r--r-- | src/SMAPI/Framework/Serialisation/Converters/StringEnumConverter.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Serialisation/Converters/StringEnumConverter.cs b/src/SMAPI/Framework/Serialisation/Converters/StringEnumConverter.cs new file mode 100644 index 00000000..0a612c74 --- /dev/null +++ b/src/SMAPI/Framework/Serialisation/Converters/StringEnumConverter.cs @@ -0,0 +1,22 @@ +using System; +using Newtonsoft.Json.Converters; + +namespace StardewModdingAPI.Framework.Serialisation.Converters +{ + /// <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); + } + } +} |