diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-06-18 22:08:56 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-06-18 22:08:56 -0400 |
commit | b46776a4fbabe765b81751f8c4984cdd8a207419 (patch) | |
tree | 1f0cfbec3f78c1e14a8d6d232a81b48207aa488f /src/StardewModdingAPI | |
parent | 3e50c90230bf4f7aa4efb69b3db47dddd1e43750 (diff) | |
download | SMAPI-b46776a4fbabe765b81751f8c4984cdd8a207419.tar.gz SMAPI-b46776a4fbabe765b81751f8c4984cdd8a207419.tar.bz2 SMAPI-b46776a4fbabe765b81751f8c4984cdd8a207419.zip |
enable string versions in manifest.json (#308)
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r-- | src/StardewModdingAPI/Framework/Serialisation/ManifestFieldConverter.cs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/StardewModdingAPI/Framework/Serialisation/ManifestFieldConverter.cs b/src/StardewModdingAPI/Framework/Serialisation/ManifestFieldConverter.cs index 7acb5fd0..7a59f134 100644 --- a/src/StardewModdingAPI/Framework/Serialisation/ManifestFieldConverter.cs +++ b/src/StardewModdingAPI/Framework/Serialisation/ManifestFieldConverter.cs @@ -36,12 +36,25 @@ namespace StardewModdingAPI.Framework.Serialisation // semantic version if (objectType == typeof(ISemanticVersion)) { - JObject obj = JObject.Load(reader); - int major = obj.Value<int>(nameof(ISemanticVersion.MajorVersion)); - int minor = obj.Value<int>(nameof(ISemanticVersion.MinorVersion)); - int patch = obj.Value<int>(nameof(ISemanticVersion.PatchVersion)); - string build = obj.Value<string>(nameof(ISemanticVersion.Build)); - return new SemanticVersion(major, minor, patch, build); + JToken token = JToken.Load(reader); + switch (token.Type) + { + case JTokenType.Object: + { + JObject obj = (JObject)token; + int major = obj.Value<int>(nameof(ISemanticVersion.MajorVersion)); + int minor = obj.Value<int>(nameof(ISemanticVersion.MinorVersion)); + int patch = obj.Value<int>(nameof(ISemanticVersion.PatchVersion)); + string build = obj.Value<string>(nameof(ISemanticVersion.Build)); + return new SemanticVersion(major, minor, patch, build); + } + + case JTokenType.String: + return new SemanticVersion(token.Value<string>()); + + default: + throw new FormatException($"Can't parse {token.Type} token as a semantic version, must be an object or string."); + } } // manifest dependency |