summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/SemanticVersion.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-08-21 16:39:21 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-08-21 16:39:21 -0400
commit8ba54a682fd7de3756b6ddd262b232cf40d23ea0 (patch)
tree7e44d53b733d95b05b232da46306a0d3d57e9231 /src/StardewModdingAPI/SemanticVersion.cs
parent674ad0d90f8780130a5fcefb3869acfe2315df2a (diff)
parenteea5100acea0bceaf440f9d1bd50ee2b24cf8ebc (diff)
downloadSMAPI-8ba54a682fd7de3756b6ddd262b232cf40d23ea0.tar.gz
SMAPI-8ba54a682fd7de3756b6ddd262b232cf40d23ea0.tar.bz2
SMAPI-8ba54a682fd7de3756b6ddd262b232cf40d23ea0.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/SemanticVersion.cs')
-rw-r--r--src/StardewModdingAPI/SemanticVersion.cs33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/StardewModdingAPI/SemanticVersion.cs b/src/StardewModdingAPI/SemanticVersion.cs
index 4b27c819..e448eae1 100644
--- a/src/StardewModdingAPI/SemanticVersion.cs
+++ b/src/StardewModdingAPI/SemanticVersion.cs
@@ -1,5 +1,6 @@
-using System;
+using System;
using System.Text.RegularExpressions;
+using Newtonsoft.Json;
namespace StardewModdingAPI
{
@@ -17,7 +18,7 @@ namespace StardewModdingAPI
/// - allows hyphens in prerelease tags as synonyms for dots (like "-unofficial-update.3");
/// - doesn't allow '+build' suffixes.
/// </remarks>
- private static readonly Regex Regex = new Regex(@"^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)(\.(?<patch>0|[1-9]\d*))?(?:-(?<prerelease>([a-z0-9]+[\-\.]?)+))?$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
+ private static readonly Regex Regex = new Regex(@"^(?>(?<major>0|[1-9]\d*))\.(?>(?<minor>0|[1-9]\d*))(?>(?:\.(?<patch>0|[1-9]\d*))?)(?:-(?<prerelease>(?>[a-z0-9]+[\-\.]?)+))?$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
/*********
@@ -40,15 +41,16 @@ namespace StardewModdingAPI
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- /// <param name="major">The major version incremented for major API changes.</param>
- /// <param name="minor">The minor version incremented for backwards-compatible changes.</param>
- /// <param name="patch">The patch version for backwards-compatible bug fixes.</param>
+ /// <param name="majorVersion">The major version incremented for major API changes.</param>
+ /// <param name="minorVersion">The minor version incremented for backwards-compatible changes.</param>
+ /// <param name="patchVersion">The patch version for backwards-compatible bug fixes.</param>
/// <param name="build">An optional build tag.</param>
- public SemanticVersion(int major, int minor, int patch, string build = null)
+ [JsonConstructor]
+ public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string build = null)
{
- this.MajorVersion = major;
- this.MinorVersion = minor;
- this.PatchVersion = patch;
+ this.MajorVersion = majorVersion;
+ this.MinorVersion = minorVersion;
+ this.PatchVersion = patchVersion;
this.Build = this.GetNormalisedTag(build);
}
@@ -117,8 +119,7 @@ namespace StardewModdingAPI
{
// compare numerically if possible
{
- int curNum, otherNum;
- if (int.TryParse(curParts[i], out curNum) && int.TryParse(otherParts[i], out otherNum))
+ if (int.TryParse(curParts[i], out int curNum) && int.TryParse(otherParts[i], out int otherNum))
return curNum.CompareTo(otherNum);
}
@@ -178,6 +179,16 @@ namespace StardewModdingAPI
return this.IsBetween(new SemanticVersion(min), new SemanticVersion(max));
}
+#if !SMAPI_1_x
+ /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
+ /// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
+ /// <param name="other">An object to compare with this object.</param>
+ public bool Equals(ISemanticVersion other)
+ {
+ return other != null && this.CompareTo(other) == 0;
+ }
+#endif
+
/// <summary>Get a string representation of the version.</summary>
public override string ToString()
{