Class SemanticVersion
Implements a semantic version as defined by the Semantic Versioning 2.0.0 specification. This is similar to the base Version class but includes support for pre-release identifiers as well as build information.
Namespace: Neon.Common
Assembly: Neon.Common.dll
Syntax
public class SemanticVersion
Constructors
SemanticVersion()
Default constuctor.
Declaration
public SemanticVersion()
Properties
Build
The build information or null
.
note
Build information does not include the prefix plus (+) sign.
Declaration
public string Build { get; set; }
Property Value
Type | Description |
---|---|
string |
IsPrerelease
Indicates whether the version specifies a prerelease.
Declaration
public bool IsPrerelease { get; }
Property Value
Type | Description |
---|---|
bool |
Major
The major version number.
Declaration
public int Major { get; set; }
Property Value
Type | Description |
---|---|
int |
Minor
The minor version number.
Declaration
public int Minor { get; set; }
Property Value
Type | Description |
---|---|
int |
Numeric
Returns only the numeric part of the semantic version, excluding any prerelase or build parts.
Declaration
public string Numeric { get; }
Property Value
Type | Description |
---|---|
string |
Patch
The patch version number.
Declaration
public int Patch { get; set; }
Property Value
Type | Description |
---|---|
int |
Prerelease
The prerelease identifer or null
.
note
Prerelease identifiers do not include the prefix dash (-).
Declaration
public string Prerelease { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
Compare(SemanticVersion, SemanticVersion)
Compares two non-null semantic versions.
Declaration
public static int Compare(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | The first version. |
SemanticVersion | v2 | The second version. |
Returns
Type | Description |
---|---|
int | -1 if |
Remarks
note
A null
version is considered to be less than a non-null version.
CompareTo(object)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Declaration
public int CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | An object to compare with this instance. |
Returns
Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
int | A value that indicates the relative order of the objects being compared. The return value has these meanings:
|
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
Create(int, int, int, string, string)
Creates a semantic version number from parameters.
Declaration
public static SemanticVersion Create(int major, int minor = 0, int patch = 0, string build = null, string prerelease = null)
Parameters
Type | Name | Description |
---|---|---|
int | major | The major version. |
int | minor | Optional minor version. |
int | patch | Optional patch version. |
string | build | Optional build. |
string | prerelease | Optional prerelease. |
Returns
Type | Description |
---|---|
SemanticVersion | The SemanticVersion. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if any of the parameters are invalid. |
Equals(object)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
Parse(string)
Parses a semantic version string.
Declaration
public static SemanticVersion Parse(string versionText)
Parameters
Type | Name | Description |
---|---|---|
string | versionText | The version text. |
Returns
Type | Description |
---|---|
SemanticVersion | The parsed SemanticVersion. |
Exceptions
Type | Condition |
---|---|
FormatException | Thrown if the version could not be parsed. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |
Overrides
TryParse(string, out SemanticVersion)
Attempts to parse a semantic version string.
Declaration
public static bool TryParse(string versionText, out SemanticVersion version)
Parameters
Type | Name | Description |
---|---|---|
string | versionText | The version text. |
SemanticVersion | version | Returns as the parsed version on success. |
Returns
Type | Description |
---|---|
bool |
|
Operators
operator ==(SemanticVersion, SemanticVersion)
Compares two SemanticVersion instances for equality.
Declaration
public static bool operator ==(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | Version #1. |
SemanticVersion | v2 | Version #2. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Throw if either parameter is |
explicit operator string(SemanticVersion)
Explicitly casts a SemanticVersion into a string.
Declaration
public static explicit operator string(SemanticVersion version)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | version | The version input. |
Returns
Type | Description |
---|---|
string | The version converted to a string. |
explicit operator SemanticVersion(string)
Explicitly casts a string into a SemanticVersion.
Declaration
public static explicit operator SemanticVersion(string version)
Parameters
Type | Name | Description |
---|---|---|
string | version | The version input. |
Returns
Type | Description |
---|---|
SemanticVersion | The string converted to a SemanticVersion. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
operator >(SemanticVersion, SemanticVersion)
Compares two SemanticVersion instances to see if the first is greater.
Declaration
public static bool operator >(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | Version #1. |
SemanticVersion | v2 | Version #2. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Throw if either parameter is |
operator >=(SemanticVersion, SemanticVersion)
Compares two SemanticVersion instances to see if the first is greater or equal.
Declaration
public static bool operator >=(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | Version #1. |
SemanticVersion | v2 | Version #2. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Throw if either parameter is |
operator !=(SemanticVersion, SemanticVersion)
Compares two SemanticVersion instances for inequality.
Declaration
public static bool operator !=(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | Version #1. |
SemanticVersion | v2 | Version #2. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Throw if either parameter is |
operator <(SemanticVersion, SemanticVersion)
Compares two SemanticVersion instances to see if the first is less.
Declaration
public static bool operator <(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | Version #1. |
SemanticVersion | v2 | Version #2. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Throw if either parameter is |
operator <=(SemanticVersion, SemanticVersion)
Compares two SemanticVersion instances to see if the first is less or equal.
Declaration
public static bool operator <=(SemanticVersion v1, SemanticVersion v2)
Parameters
Type | Name | Description |
---|---|---|
SemanticVersion | v1 | Version #1. |
SemanticVersion | v2 | Version #2. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Throw if either parameter is |