summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-06 23:47:12 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-06 23:47:12 -0400
commitd1a7194bf604ac9f960c45de0c82e6eaddd5ff5a (patch)
treefd8749686a8a0b86e48e06860e5d84f522119277 /src/SMAPI.Toolkit
parentb4e979cc991a0c2a45ad986210108edd2d43e43d (diff)
downloadSMAPI-d1a7194bf604ac9f960c45de0c82e6eaddd5ff5a.tar.gz
SMAPI-d1a7194bf604ac9f960c45de0c82e6eaddd5ff5a.tar.bz2
SMAPI-d1a7194bf604ac9f960c45de0c82e6eaddd5ff5a.zip
allow null values in ISemanticVersion compare methods (#837)
Diffstat (limited to 'src/SMAPI.Toolkit')
-rw-r--r--src/SMAPI.Toolkit/SemanticVersion.cs27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/SMAPI.Toolkit/SemanticVersion.cs b/src/SMAPI.Toolkit/SemanticVersion.cs
index 97b92555..41ae12eb 100644
--- a/src/SMAPI.Toolkit/SemanticVersion.cs
+++ b/src/SMAPI.Toolkit/SemanticVersion.cs
@@ -108,9 +108,9 @@ namespace StardewModdingAPI.Toolkit
/// <inheritdoc />
public int CompareTo(ISemanticVersion other)
{
- if (other == null)
- throw new ArgumentNullException(nameof(other));
- return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, (other as SemanticVersion)?.PlatformRelease ?? 0, other.PrereleaseTag);
+ return other == null
+ ? 1
+ : this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, (other as SemanticVersion)?.PlatformRelease ?? 0, other.PrereleaseTag);
}
/// <inheritdoc />
@@ -134,7 +134,11 @@ namespace StardewModdingAPI.Toolkit
/// <inheritdoc />
public bool IsOlderThan(string other)
{
- return this.IsOlderThan(new SemanticVersion(other, allowNonStandard: true));
+ ISemanticVersion otherVersion = other != null
+ ? new SemanticVersion(other, allowNonStandard: true)
+ : null;
+
+ return this.IsOlderThan(otherVersion);
}
/// <inheritdoc />
@@ -146,7 +150,11 @@ namespace StardewModdingAPI.Toolkit
/// <inheritdoc />
public bool IsNewerThan(string other)
{
- return this.IsNewerThan(new SemanticVersion(other, allowNonStandard: true));
+ ISemanticVersion otherVersion = other != null
+ ? new SemanticVersion(other, allowNonStandard: true)
+ : null;
+
+ return this.IsNewerThan(otherVersion);
}
/// <inheritdoc />
@@ -158,7 +166,14 @@ namespace StardewModdingAPI.Toolkit
/// <inheritdoc />
public bool IsBetween(string min, string max)
{
- return this.IsBetween(new SemanticVersion(min, allowNonStandard: true), new SemanticVersion(max, allowNonStandard: true));
+ ISemanticVersion minVersion = min != null
+ ? new SemanticVersion(min, allowNonStandard: true)
+ : null;
+ ISemanticVersion maxVersion = max != null
+ ? new SemanticVersion(max, allowNonStandard: true)
+ : null;
+
+ return this.IsBetween(minVersion, maxVersion);
}
/// <inheritdoc cref="ISemanticVersion.ToString" />