From 5125a168c544d05db3174b2db942ac7b48b5115c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 3 Nov 2016 00:31:51 -0400 Subject: use semantic versioning (#154) --- src/StardewModdingAPI/Version.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/StardewModdingAPI/Version.cs') 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 { - /// A semantic mod version with an optional build tag. + /// A semantic version with an optional release tag. public struct Version { /********* @@ -46,7 +46,30 @@ namespace StardewModdingAPI /// Get a string representation of the version. 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 + *********/ + /// Get a normalised build tag. + /// The tag to normalise. + private string GetNormalisedTag(string tag) + { + tag = tag?.Trim().Trim('-'); + if (string.IsNullOrWhiteSpace(tag) || tag == "0") + return null; + return tag; } } } -- cgit