SemVer class (Nixill.Objects)
Represents a semver 2.0.0 compatible semantic version.
Constructors
The following constructor overloads are available:
SemVer(int major, int minor, int patch)SemVer(int major, int minor, int patch, string prerelease, string build)
In both of the above, major, minor, and patch must be non-negative integers; prerelease and build must be null if omitted or otherwise follow their specifications in rules 9 and 10.
SemVer(string version)
This overload allows specifying the version as a string, which must follow a semantic version string’s rules.
Fields
BuildMetadata
readonly string - The build metadata (“237ab549spec1812” of “1.23.456+237ab549spec1812”), as defined by spec rule 10.
Major
readonly int - The major version number (“1” of “1.23.456”), as defined by spec rule 8.
Minor
readonly int - The minor version number (“23” of “1.23.456”), as defined by spec rule 7.
Patch
readonly int - The patch number (“456” of “1.23.456”), as defined by spec rule 6.
PreRelease
readonly string - The prerelease identifiers (“beta” of “1.23.456-beta”), as defined by spec rule 9.
Methods
BumpMajor()
SemVer - Creates a new SemVer representing the next major release after this one, incremented according to spec rule 8.
Returns: The copied SemVer.
BumpMinor()
SemVer - Creates a new SemVer representing the next minor release after this one, incremented according to spec rule 7.
Returns: The copied SemVer.
BumpPatch()
SemVer - Creates a new SemVer representing the next patch release after this one, incremented according to spec rule 6.
Returns: The copied SemVer.
CompareTo(SemVer)
int - Compares this SemVer to another, following spec rule 11.
Parameters:
SemVertarget- The SemVer to which this one should be compared.
Returns: An int that is negative if this represents an older version than target, 0 if this and target represent the same version, and positive if this represents a newer version than target.
Equals(object)
bool - Compares this SemVer to another.
This check follows spec rule 11. Notably, this means that build metadata is ignored for the purposes of the check. Use EqualsStrict() to include build metadata.
Parameters:
objectobj- The other object to which this should be compared. Should be aSemVer.
Returns: true iff the two SemVers are equal; false otherwise.
Exceptions:
InvalidCastException:objis not aSemVer.
EqualsStrict(SemVer)
bool - Compares this SemVer to another.
This check does not follow spec rule 11. Instead, build metadata is included in this check. Use Equals() to exclude build metadata and follow rule 11.
Parameters:
SemVertarget- The other SemVer to which this should be compared.
Returns: true iff the two SemVers are equal; false otherwise.
GetHashCode()
int - Gets the hash code of this SemVer.
Since Equals() follows rule 11, this function also ignores the build metadata, to comply with the contract between Equals and GetHashCode.
Returns: A hash code for this SemVer.
Release()
SemVer - Creates a copy of this SemVer with no pre-release tag or build metadata.
Returns: The copied SemVer.
ToString()
string - Converts the SemVer to a string.
Returns: The string representation of the SemVer.
WithBuildMetadata(string)
SemVer - Returns a new copy of this SemVer with the specified build metadata tag, leaving the other fields unchanged.
Parameters:
intbuild- The build metadata to use. Specifynullto remove the build metadata tag.
Returns: The adjusted SemVer.
WithMajor(int)
SemVer - Returns a new copy of this SemVer with the specified major version number, leaving the other fields unchanged.
Parameters:
intmaj- The major version to use.
Returns: The adjusted SemVer.
WithMinor(int)
SemVer - Returns a new copy of this SemVer with the specified minor version number, leaving the other fields unchanged.
Parameters:
intmin- The minor version to use.
Returns: The adjusted SemVer.
WithPatch(int)
SemVer - Returns a new copy of this SemVer with the specified patch number, leaving the other fields unchanged.
Parameters:
intpat- The patch to use.
Returns: The adjusted SemVer.
WithPreRelease(string)
SemVer - Returns a new copy of this SemVer with the specified pre-release tag, leaving the other fields unchanged.
Parameters:
stringpr- The pre-release tag to use. Specifynullto remove the pre-release tag.
Returns: The adjusted SemVer.
Operators
Binary operators
- (
bool)SemVer left == SemVer right- Returns true iffleftandrightrepresent the same version, ignoring the build metadata. - (
bool)SemVer left != SemVer right- Returns true iffleftandrightrepresent different versions, ignoring the build metadata. - (
bool)SemVer left < SemVer right- Returns true iffleftrepresents an earlier version thanright. - (
bool)SemVer left <= SemVer right- Returns true iffleftrepresents an earlier version thanright, or the same version. - (
bool)SemVer left > SemVer right- Returns true iffleftrepresents a later version thanright. - (
bool)SemVer left >= SemVer right- Returns true iffleftrepresents a later version thanright, or the same version.