summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Toolkit/SemanticVersion.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI.Toolkit/SemanticVersion.cs')
-rw-r--r--src/StardewModdingAPI.Toolkit/SemanticVersion.cs38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs
index a7990d13..19da0a76 100644
--- a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs
+++ b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs
@@ -40,14 +40,16 @@ namespace StardewModdingAPI.Toolkit
public int PatchVersion { get; }
/// <summary>An optional prerelease tag.</summary>
- [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")]
- public string Build => this.PrereleaseTag;
+ public string PrereleaseTag { get; }
+#if !SMAPI_3_0_STRICT
/// <summary>An optional prerelease tag.</summary>
- public string PrereleaseTag { get; }
+ [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")]
+ public string Build => this.PrereleaseTag;
/// <summary>Whether the version was parsed from the legacy object format.</summary>
public bool IsLegacyFormat { get; }
+#endif
/*********
@@ -57,15 +59,21 @@ namespace StardewModdingAPI.Toolkit
/// <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 fixes.</param>
- /// <param name="tag">An optional prerelease tag.</param>
+ /// <param name="prereleaseTag">An optional prerelease tag.</param>
/// <param name="isLegacyFormat">Whether the version was parsed from the legacy object format.</param>
- public SemanticVersion(int major, int minor, int patch, string tag = null, bool isLegacyFormat = false)
+ public SemanticVersion(int major, int minor, int patch, string prereleaseTag = null
+#if !SMAPI_3_0_STRICT
+ , bool isLegacyFormat = false
+#endif
+ )
{
this.MajorVersion = major;
this.MinorVersion = minor;
this.PatchVersion = patch;
- this.PrereleaseTag = this.GetNormalisedTag(tag);
+ this.PrereleaseTag = this.GetNormalisedTag(prereleaseTag);
+#if !SMAPI_3_0_STRICT
this.IsLegacyFormat = isLegacyFormat;
+#endif
this.AssertValid();
}
@@ -114,7 +122,7 @@ namespace StardewModdingAPI.Toolkit
{
if (other == null)
throw new ArgumentNullException(nameof(other));
- return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.Build);
+ return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.PrereleaseTag);
}
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
@@ -128,7 +136,7 @@ namespace StardewModdingAPI.Toolkit
/// <summary>Whether this is a pre-release version.</summary>
public bool IsPrerelease()
{
- return !string.IsNullOrWhiteSpace(this.Build);
+ return !string.IsNullOrWhiteSpace(this.PrereleaseTag);
}
/// <summary>Get whether this version is older than the specified version.</summary>
@@ -187,7 +195,7 @@ namespace StardewModdingAPI.Toolkit
: $"{this.MajorVersion}.{this.MinorVersion}";
// tag
- string tag = this.Build;
+ string tag = this.PrereleaseTag;
if (tag != null)
result += $"-{tag}";
return result;
@@ -241,11 +249,11 @@ namespace StardewModdingAPI.Toolkit
return this.MinorVersion.CompareTo(otherMinor);
if (this.PatchVersion != otherPatch)
return this.PatchVersion.CompareTo(otherPatch);
- if (this.Build == otherTag)
+ if (this.PrereleaseTag == otherTag)
return same;
// stable supercedes pre-release
- bool curIsStable = string.IsNullOrWhiteSpace(this.Build);
+ bool curIsStable = string.IsNullOrWhiteSpace(this.PrereleaseTag);
bool otherIsStable = string.IsNullOrWhiteSpace(otherTag);
if (curIsStable)
return curNewer;
@@ -253,7 +261,7 @@ namespace StardewModdingAPI.Toolkit
return curOlder;
// compare two pre-release tag values
- string[] curParts = this.Build.Split('.', '-');
+ string[] curParts = this.PrereleaseTag.Split('.', '-');
string[] otherParts = otherTag.Split('.', '-');
for (int i = 0; i < curParts.Length; i++)
{
@@ -292,11 +300,11 @@ namespace StardewModdingAPI.Toolkit
throw new FormatException($"{this} isn't a valid semantic version. The major, minor, and patch numbers can't be negative.");
if (this.MajorVersion == 0 && this.MinorVersion == 0 && this.PatchVersion == 0)
throw new FormatException($"{this} isn't a valid semantic version. At least one of the major, minor, and patch numbers must be more than zero.");
- if (this.Build != null)
+ if (this.PrereleaseTag != null)
{
- if (this.Build.Trim() == "")
+ if (this.PrereleaseTag.Trim() == "")
throw new FormatException($"{this} isn't a valid semantic version. The tag cannot be a blank string (but may be omitted).");
- if (!Regex.IsMatch(this.Build, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase))
+ if (!Regex.IsMatch(this.PrereleaseTag, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase))
throw new FormatException($"{this} isn't a valid semantic version. The tag is invalid.");
}
}