summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-23 22:04:56 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-23 22:04:56 -0400
commit085ae07251c9972bed941e33103f41724d8cd320 (patch)
treeccc63c442f1f0fd64edd69130ad1c28ed622b61e /src
parent5ff3184c301d382f6be528486bdd3139ef2ee2ff (diff)
downloadSMAPI-085ae07251c9972bed941e33103f41724d8cd320.tar.gz
SMAPI-085ae07251c9972bed941e33103f41724d8cd320.tar.bz2
SMAPI-085ae07251c9972bed941e33103f41724d8cd320.zip
add string overloads for version methods (#263)
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI/ISemanticVersion.cs16
-rw-r--r--src/StardewModdingAPI/SemanticVersion.cs27
2 files changed, 42 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/ISemanticVersion.cs b/src/StardewModdingAPI/ISemanticVersion.cs
index 24e6442a..27a2f67d 100644
--- a/src/StardewModdingAPI/ISemanticVersion.cs
+++ b/src/StardewModdingAPI/ISemanticVersion.cs
@@ -28,15 +28,31 @@ namespace StardewModdingAPI
/// <param name="other">The version to compare with this instance.</param>
bool IsOlderThan(ISemanticVersion other);
+ /// <summary>Get whether this version is older than the specified version.</summary>
+ /// <param name="other">The version to compare with this instance.</param>
+ /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception>
+ bool IsOlderThan(string other);
+
/// <summary>Get whether this version is newer than the specified version.</summary>
/// <param name="other">The version to compare with this instance.</param>
bool IsNewerThan(ISemanticVersion other);
+ /// <summary>Get whether this version is newer than the specified version.</summary>
+ /// <param name="other">The version to compare with this instance.</param>
+ /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception>
+ bool IsNewerThan(string other);
+
/// <summary>Get whether this version is between two specified versions (inclusively).</summary>
/// <param name="min">The minimum version.</param>
/// <param name="max">The maximum version.</param>
bool IsBetween(ISemanticVersion min, ISemanticVersion max);
+ /// <summary>Get whether this version is between two specified versions (inclusively).</summary>
+ /// <param name="min">The minimum version.</param>
+ /// <param name="max">The maximum version.</param>
+ /// <exception cref="FormatException">One of the specified versions is not a valid semantic version.</exception>
+ bool IsBetween(string min, string max);
+
/// <summary>Get a string representation of the version.</summary>
string ToString();
}
diff --git a/src/StardewModdingAPI/SemanticVersion.cs b/src/StardewModdingAPI/SemanticVersion.cs
index f6bfb04d..db25dc11 100644
--- a/src/StardewModdingAPI/SemanticVersion.cs
+++ b/src/StardewModdingAPI/SemanticVersion.cs
@@ -67,7 +67,7 @@ namespace StardewModdingAPI
/// <remarks>The implementation is defined by Semantic Version 2.0 (http://semver.org/).</remarks>
public int CompareTo(ISemanticVersion other)
{
- if(other == null)
+ if (other == null)
throw new ArgumentNullException(nameof(other));
const int same = 0;
@@ -127,6 +127,14 @@ namespace StardewModdingAPI
return this.CompareTo(other) < 0;
}
+ /// <summary>Get whether this version is older than the specified version.</summary>
+ /// <param name="other">The version to compare with this instance.</param>
+ /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception>
+ public bool IsOlderThan(string other)
+ {
+ return this.IsOlderThan(new SemanticVersion(other));
+ }
+
/// <summary>Get whether this version is newer than the specified version.</summary>
/// <param name="other">The version to compare with this instance.</param>
public bool IsNewerThan(ISemanticVersion other)
@@ -134,6 +142,14 @@ namespace StardewModdingAPI
return this.CompareTo(other) > 0;
}
+ /// <summary>Get whether this version is newer than the specified version.</summary>
+ /// <param name="other">The version to compare with this instance.</param>
+ /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception>
+ public bool IsNewerThan(string other)
+ {
+ return this.IsNewerThan(new SemanticVersion(other));
+ }
+
/// <summary>Get whether this version is between two specified versions (inclusively).</summary>
/// <param name="min">The minimum version.</param>
/// <param name="max">The maximum version.</param>
@@ -142,6 +158,15 @@ namespace StardewModdingAPI
return this.CompareTo(min) >= 0 && this.CompareTo(max) <= 0;
}
+ /// <summary>Get whether this version is between two specified versions (inclusively).</summary>
+ /// <param name="min">The minimum version.</param>
+ /// <param name="max">The maximum version.</param>
+ /// <exception cref="FormatException">One of the specified versions is not a valid semantic version.</exception>
+ public bool IsBetween(string min, string max)
+ {
+ return this.IsBetween(new SemanticVersion(min), new SemanticVersion(max));
+ }
+
/// <summary>Get a string representation of the version.</summary>
public override string ToString()
{