diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-18 16:47:32 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-18 16:47:32 -0400 |
commit | 51a2c3991f3c76197afb21a42a30f2a91a7f9908 (patch) | |
tree | 59bb937c35675d6376ea280e521c8cc52a1eb34a /src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs | |
parent | 2ff937397163f0ad5940b636bc7312ac747d9c39 (diff) | |
download | SMAPI-51a2c3991f3c76197afb21a42a30f2a91a7f9908.tar.gz SMAPI-51a2c3991f3c76197afb21a42a30f2a91a7f9908.tar.bz2 SMAPI-51a2c3991f3c76197afb21a42a30f2a91a7f9908.zip |
simplify SelectiveStringEnumConverter implementation
Diffstat (limited to 'src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs')
-rw-r--r-- | src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs b/src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs index 37108556..e825c880 100644 --- a/src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs +++ b/src/SMAPI/Framework/Serialisation/SelectiveStringEnumConverter.cs @@ -1,37 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System; using Newtonsoft.Json.Converters; namespace StardewModdingAPI.Framework.Serialisation { - /// <summary>A variant of <see cref="StringEnumConverter"/> which only converts certain enums.</summary> - internal class SelectiveStringEnumConverter : StringEnumConverter + /// <summary>A variant of <see cref="StringEnumConverter"/> which only converts a specified enum.</summary> + /// <typeparam name="T">The enum type.</typeparam> + internal class SelectiveStringEnumConverter<T> : StringEnumConverter { /********* - ** Properties - *********/ - /// <summary>The enum type names to convert.</summary> - private readonly HashSet<string> Types; - - - /********* ** Public methods *********/ - /// <summary>Construct an instance.</summary> - /// <param name="types">The enum types to convert.</param> - public SelectiveStringEnumConverter(params Type[] types) - { - this.Types = new HashSet<string>(types.Select(p => p.FullName)); - } - /// <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) - && this.Types.Contains((Nullable.GetUnderlyingType(type) ?? type).FullName); + && (Nullable.GetUnderlyingType(type) ?? type) == typeof(T); } } } |