Class SemVersion
A semantic version implementation. Conforms to v2.0.0 of http://semver.org/
Inheritance
Namespace: Umbraco.Cms.Core.Semver
Assembly: Umbraco.Core.dll
Syntax
public sealed class SemVersion : IComparable<SemVersion>, ISerializable
Constructors
View SourceSemVersion(Int32, Int32, Int32, String, String)
Initializes a new instance of the SemVersion class.
Declaration
public SemVersion(int major, int minor = 0, int patch = 0, string prerelease = "", string build = "")
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | major | The major version. |
| System.Int32 | minor | The minor version. |
| System.Int32 | patch | The patch version. |
| System.String | prerelease | The prerelease version (eg. "alpha"). |
| System.String | build | The build eg ("nightly.232"). |
SemVersion(Version)
Initializes a new instance of the SemVersion class.
Declaration
public SemVersion(Version version)
Parameters
| Type | Name | Description |
|---|---|---|
| Version | version | The System.Version that is used to initialize the Major, Minor, Patch and Build properties. |
Properties
View SourceBuild
Gets the build version.
Declaration
public string Build { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The build version. |
Major
Gets the major version.
Declaration
public int Major { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The major version. |
Minor
Gets the minor version.
Declaration
public int Minor { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The minor version. |
Patch
Gets the patch version.
Declaration
public int Patch { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The patch version. |
Prerelease
Gets the pre-release version.
Declaration
public string Prerelease { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The pre-release version. |
Methods
View SourceChange(Nullable<Int32>, Nullable<Int32>, Nullable<Int32>, String, String)
Make a copy of the current instance with optional altered fields.
Declaration
public SemVersion Change(int? major = null, int? minor = null, int? patch = null, string prerelease = null, string build = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Nullable<System.Int32> | major | The major version. |
| System.Nullable<System.Int32> | minor | The minor version. |
| System.Nullable<System.Int32> | patch | The patch version. |
| System.String | prerelease | The prerelease text. |
| System.String | build | The build text. |
Returns
| Type | Description |
|---|---|
| SemVersion | The new version object. |
Compare(SemVersion, SemVersion)
Compares the specified versions.
Declaration
public static int Compare(SemVersion versionA, SemVersion versionB)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | versionA | The version to compare to. |
| SemVersion | versionB | The version to compare against. |
Returns
| Type | Description |
|---|---|
| System.Int32 | If versionA < versionB |
CompareByPrecedence(SemVersion)
Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information.
Declaration
public int CompareByPrecedence(SemVersion other)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | other | The semantic version. |
Returns
| Type | Description |
|---|---|
| System.Int32 | A value that indicates the relative order of the objects being compared.
The return value has these meanings: Value Meaning Less than zero
This instance precedes |
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 |
|---|---|---|
| System.Object | obj | An object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| System.Int32 | A value that indicates the relative order of the objects being compared.
The return value has these meanings: Value Meaning Less than zero
This instance precedes |
CompareTo(SemVersion)
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(SemVersion other)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | other | An object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| System.Int32 | A value that indicates the relative order of the objects being compared.
The return value has these meanings: Value Meaning Less than zero
This instance precedes |
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The System.Object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Equals(SemVersion, SemVersion)
Tests the specified versions for equality.
Declaration
public static bool Equals(SemVersion versionA, SemVersion versionB)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | versionA | The first version. |
| SemVersion | versionB | The second version. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If versionA is equal to versionB |
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
GetObjectData(SerializationInfo, StreamingContext)
Declaration
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Runtime.Serialization.SerializationInfo | info | |
| System.Runtime.Serialization.StreamingContext | context |
Parse(String, Boolean)
Parses the specified string to a semantic version.
Declaration
public static SemVersion Parse(string version, bool strict = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | version | The version string. |
| System.Boolean | strict | If set to |
Returns
| Type | Description |
|---|---|
| SemVersion | The SemVersion object. |
Exceptions
| Type | Condition |
|---|---|
| System.InvalidOperationException | When a invalid version string is passed. |
PrecedenceMatches(SemVersion)
Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build information.
Declaration
public bool PrecedenceMatches(SemVersion other)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | other | The semantic version. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A System.String that represents this instance. |
TryParse(String, out SemVersion, Boolean)
Parses the specified string to a semantic version.
Declaration
public static bool TryParse(string version, out SemVersion semver, bool strict = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | version | The version string. |
| SemVersion | semver | When the method returns, contains a SemVersion instance equivalent
to the version string passed in, if the version string was valid, or |
| System.Boolean | strict | If set to |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Operators
View SourceEquality(SemVersion, SemVersion)
The override of the equals operator.
Declaration
public static bool operator ==(SemVersion left, SemVersion right)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | left | The left value. |
| SemVersion | right | The right value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If left is equal to right |
GreaterThan(SemVersion, SemVersion)
The override of the greater operator.
Declaration
public static bool operator>(SemVersion left, SemVersion right)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | left | The left value. |
| SemVersion | right | The right value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If left is greater than right |
GreaterThanOrEqual(SemVersion, SemVersion)
The override of the greater than or equal operator.
Declaration
public static bool operator >=(SemVersion left, SemVersion right)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | left | The left value. |
| SemVersion | right | The right value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If left is greater than or equal to right |
Implicit(String to SemVersion)
Implicit conversion from string to SemVersion.
Declaration
public static implicit operator SemVersion(string version)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | version | The semantic version. |
Returns
| Type | Description |
|---|---|
| SemVersion | The SemVersion object. |
Inequality(SemVersion, SemVersion)
The override of the un-equal operator.
Declaration
public static bool operator !=(SemVersion left, SemVersion right)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | left | The left value. |
| SemVersion | right | The right value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If left is not equal to right |
LessThan(SemVersion, SemVersion)
The override of the less operator.
Declaration
public static bool operator <(SemVersion left, SemVersion right)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | left | The left value. |
| SemVersion | right | The right value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If left is less than right |
LessThanOrEqual(SemVersion, SemVersion)
The override of the less than or equal operator.
Declaration
public static bool operator <=(SemVersion left, SemVersion right)
Parameters
| Type | Name | Description |
|---|---|---|
| SemVersion | left | The left value. |
| SemVersion | right | The right value. |
Returns
| Type | Description |
|---|---|
| System.Boolean | If left is less than or equal to right |