diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-03 00:31:51 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-03 00:31:51 -0400 |
commit | 5125a168c544d05db3174b2db942ac7b48b5115c (patch) | |
tree | a34114cf9823644a0bb9940909c2ba4d713caec3 /src | |
parent | 88e57cf84a777636ce6e66bb97f20272657a2c2f (diff) | |
download | SMAPI-5125a168c544d05db3174b2db942ac7b48b5115c.tar.gz SMAPI-5125a168c544d05db3174b2db942ac7b48b5115c.tar.bz2 SMAPI-5125a168c544d05db3174b2db942ac7b48b5115c.zip |
use semantic versioning (#154)
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Version.cs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/StardewModdingAPI/Version.cs b/src/StardewModdingAPI/Version.cs index cce68ad8..db5a21d4 100644 --- a/src/StardewModdingAPI/Version.cs +++ b/src/StardewModdingAPI/Version.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; namespace StardewModdingAPI { - /// <summary>A semantic mod version with an optional build tag.</summary> + /// <summary>A semantic version with an optional release tag.</summary> public struct Version { /********* @@ -46,7 +46,30 @@ namespace StardewModdingAPI /// <summary>Get a string representation of the version.</summary> public override string ToString() { - return $"{this.MajorVersion}.{this.MinorVersion}.{this.PatchVersion} {this.Build}".Trim(); + // version + string result = this.PatchVersion != 0 + ? $"{this.MajorVersion}.{this.MinorVersion}.{this.PatchVersion}" + : $"{this.MajorVersion}.{this.MinorVersion}"; + + // tag + string tag = this.GetNormalisedTag(this.Build); + if (tag != null) + result += $"-{tag}"; + return result; + } + + + /********* + ** Private methods + *********/ + /// <summary>Get a normalised build tag.</summary> + /// <param name="tag">The tag to normalise.</param> + private string GetNormalisedTag(string tag) + { + tag = tag?.Trim().Trim('-'); + if (string.IsNullOrWhiteSpace(tag) || tag == "0") + return null; + return tag; } } } |