From ab6cf45b03073f324c46f9e93a98e3342a1bdff7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 7 Apr 2022 00:56:00 -0400 Subject: enable nullable annotations for semantic versions (#837) --- src/SMAPI/SemanticVersion.cs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs index 4e484633..7a6cdcdd 100644 --- a/src/SMAPI/SemanticVersion.cs +++ b/src/SMAPI/SemanticVersion.cs @@ -1,6 +1,5 @@ -#nullable disable - using System; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace StardewModdingAPI @@ -28,10 +27,10 @@ namespace StardewModdingAPI public int PatchVersion => this.Version.PatchVersion; /// - public string PrereleaseTag => this.Version.PrereleaseTag; + public string? PrereleaseTag => this.Version.PrereleaseTag; /// - public string BuildMetadata => this.Version.BuildMetadata; + public string? BuildMetadata => this.Version.BuildMetadata; /********* @@ -43,7 +42,7 @@ namespace StardewModdingAPI /// The patch version for backwards-compatible bug fixes. /// An optional prerelease tag. /// Optional build metadata. This is ignored when determining version precedence. - public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string prereleaseTag = null, string buildMetadata = null) + public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string? prereleaseTag = null, string? buildMetadata = null) : this(majorVersion, minorVersion, patchVersion, 0, prereleaseTag, buildMetadata) { } /// Construct an instance. @@ -54,7 +53,7 @@ namespace StardewModdingAPI /// The platform-specific version (if applicable). /// Optional build metadata. This is ignored when determining version precedence. [JsonConstructor] - internal SemanticVersion(int majorVersion, int minorVersion, int patchVersion, int platformRelease, string prereleaseTag = null, string buildMetadata = null) + internal SemanticVersion(int majorVersion, int minorVersion, int patchVersion, int platformRelease, string? prereleaseTag = null, string? buildMetadata = null) : this(new Toolkit.SemanticVersion(majorVersion, minorVersion, patchVersion, platformRelease, prereleaseTag, buildMetadata)) { } /// Construct an instance. @@ -93,49 +92,49 @@ namespace StardewModdingAPI /// /// The implementation is defined by Semantic Version 2.0 (https://semver.org/). - public int CompareTo(ISemanticVersion other) + public int CompareTo(ISemanticVersion? other) { return this.Version.CompareTo(other); } /// - public bool IsOlderThan(ISemanticVersion other) + public bool IsOlderThan(ISemanticVersion? other) { return this.Version.IsOlderThan(other); } /// - public bool IsOlderThan(string other) + public bool IsOlderThan(string? other) { return this.Version.IsOlderThan(other); } /// - public bool IsNewerThan(ISemanticVersion other) + public bool IsNewerThan(ISemanticVersion? other) { return this.Version.IsNewerThan(other); } /// - public bool IsNewerThan(string other) + public bool IsNewerThan(string? other) { return this.Version.IsNewerThan(other); } /// - public bool IsBetween(ISemanticVersion min, ISemanticVersion max) + public bool IsBetween(ISemanticVersion? min, ISemanticVersion? max) { return this.Version.IsBetween(min, max); } /// - public bool IsBetween(string min, string max) + public bool IsBetween(string? min, string? max) { return this.Version.IsBetween(min, max); } /// - public bool Equals(ISemanticVersion other) + public bool Equals(ISemanticVersion? other) { return other != null && this.CompareTo(other) == 0; } @@ -156,9 +155,9 @@ namespace StardewModdingAPI /// The version string. /// The parsed representation. /// Returns whether parsing the version succeeded. - public static bool TryParse(string version, out ISemanticVersion parsed) + public static bool TryParse(string version, [NotNullWhen(true)] out ISemanticVersion? parsed) { - if (Toolkit.SemanticVersion.TryParse(version, out ISemanticVersion versionImpl)) + if (Toolkit.SemanticVersion.TryParse(version, out ISemanticVersion? versionImpl)) { parsed = new SemanticVersion(versionImpl); return true; -- cgit