summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Serialisation/StringEnumConverter.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-11-01 17:42:18 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-11-01 17:42:18 -0400
commite0b72374cd14298aacc6f71dc391fdc9814be37c (patch)
tree2e5d85937c34539c1a0df48423b5136508693ca8 /src/SMAPI/Framework/Serialisation/StringEnumConverter.cs
parent79118316065a01322d8ea12a14589ec016794c32 (diff)
parent089e6de749ae7cb109af00164d2597c6644c255e (diff)
downloadSMAPI-e0b72374cd14298aacc6f71dc391fdc9814be37c.tar.gz
SMAPI-e0b72374cd14298aacc6f71dc391fdc9814be37c.tar.bz2
SMAPI-e0b72374cd14298aacc6f71dc391fdc9814be37c.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/Serialisation/StringEnumConverter.cs')
-rw-r--r--src/SMAPI/Framework/Serialisation/StringEnumConverter.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Serialisation/StringEnumConverter.cs b/src/SMAPI/Framework/Serialisation/StringEnumConverter.cs
new file mode 100644
index 00000000..7afe86cd
--- /dev/null
+++ b/src/SMAPI/Framework/Serialisation/StringEnumConverter.cs
@@ -0,0 +1,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);
+ }
+ }
+}