Class SemVersion
A semantic version number. Conforms with v2.0.0 of semantic versioning
(
semver.org).
Inheritance
System.Object
SemVersion
Implements
System.Runtime.Serialization.ISerializable
Assembly: Semver.dll
Syntax
public sealed class SemVersion : Object
Constructors
SemVersion(BigInteger)
Constructs a new instance of the
SemVersion class.
Declaration
public SemVersion(BigInteger major)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The major version number. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major version
number is negative. |
SemVersion(BigInteger, BigInteger)
Constructs a new instance of the
SemVersion class.
Declaration
public SemVersion(BigInteger major, BigInteger minor)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The major version number. |
| System.Numerics.BigInteger |
minor |
The minor version number. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major or
minor version number is negative. |
SemVersion(BigInteger, BigInteger, BigInteger)
Constructs a new instance of the
SemVersion class.
Declaration
public SemVersion(BigInteger major, BigInteger minor, BigInteger patch)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The major version number. |
| System.Numerics.BigInteger |
minor |
The minor version number. |
| System.Numerics.BigInteger |
patch |
The patch version number. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major,
minor, or patch version number is negative. |
Constructs a new instance of the
SemVersion class.
Declaration
public SemVersion(BigInteger major, BigInteger minor = null, BigInteger patch = null, IEnumerable<PrereleaseIdentifier> prerelease = null, IEnumerable<MetadataIdentifier> metadata = null)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The major version number. |
| System.Numerics.BigInteger |
minor |
The minor version number. |
| System.Numerics.BigInteger |
patch |
The patch version number. |
| System.Collections.Generic.IEnumerable<PrereleaseIdentifier> |
prerelease |
The prerelease identifiers. |
| System.Collections.Generic.IEnumerable<MetadataIdentifier> |
metadata |
The build metadata identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major,
minor, or patch version number is negative. |
| System.ArgumentException |
A prerelease or metadata identifier has the default value. |
SemVersion(BigInteger, BigInteger, BigInteger, IEnumerable<String>, IEnumerable<String>)
Constructs a new instance of the
SemVersion class.
Declaration
public SemVersion(BigInteger major, BigInteger minor = null, BigInteger patch = null, IEnumerable<string> prerelease = null, IEnumerable<string> metadata = null)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The major version number. |
| System.Numerics.BigInteger |
minor |
The minor version number. |
| System.Numerics.BigInteger |
patch |
The patch version number. |
| System.Collections.Generic.IEnumerable<System.String> |
prerelease |
The prerelease identifiers. |
| System.Collections.Generic.IEnumerable<System.String> |
metadata |
The build metadata identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major,
minor, or patch version number is negative. |
| System.ArgumentNullException |
One of the prerelease or metadata identifiers is null. |
| System.ArgumentException |
A prerelease identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens) or has leading
zeros for a numeric identifier. Or, a metadata identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens). |
Properties
IsPrerelease
Whether this is a prerelease version.
Declaration
public bool IsPrerelease { get; }
Property Value
| Type |
Description |
| System.Boolean |
Whether this is a prerelease version. A semantic version with
prerelease identifiers is a prerelease version. |
IsRelease
Whether this is a release version.
Declaration
public bool IsRelease { get; }
Property Value
| Type |
Description |
| System.Boolean |
Whether this is a release version. A semantic version without
prerelease identifiers is a release version. |
Major
The major version number.
Declaration
public BigInteger Major { get; }
Property Value
| Type |
Description |
| System.Numerics.BigInteger |
The major version number. |
The build metadata for this version.
Declaration
public string Metadata { get; }
Property Value
| Type |
Description |
| System.String |
The build metadata for this version or empty string if there
is no metadata. |
The build metadata identifiers for this version.
Declaration
public IReadOnlyList<MetadataIdentifier> MetadataIdentifiers { get; }
Property Value
| Type |
Description |
| System.Collections.Generic.IReadOnlyList<MetadataIdentifier> |
The build metadata identifiers for this version or empty if there
is no metadata. |
Minor
The minor version number.
Declaration
public BigInteger Minor { get; }
Property Value
| Type |
Description |
| System.Numerics.BigInteger |
The minor version number. |
Patch
The patch version number.
Declaration
public BigInteger Patch { get; }
Property Value
| Type |
Description |
| System.Numerics.BigInteger |
The patch version number. |
PrecedenceComparer
An
System.Collections.Generic.IEqualityComparer`1 and
System.Collections.Generic.IComparer`1
that compares
SemVersion by precedence. This can be used for sorting,
binary search, and using
SemVersion as a dictionary key.
Declaration
public static ISemVersionComparer PrecedenceComparer { get; }
Property Value
| Type |
Description |
| ISemVersionComparer |
A precedence comparer that implements System.Collections.Generic.IEqualityComparer`1 and
System.Collections.Generic.IComparer`1 for SemVersion. |
Prerelease
The prerelease identifiers for this version.
Declaration
public string Prerelease { get; }
Property Value
| Type |
Description |
| System.String |
The prerelease identifiers for this version or empty string if this is a release version.
|
PrereleaseIdentifiers
The prerelease identifiers for this version.
Declaration
public IReadOnlyList<PrereleaseIdentifier> PrereleaseIdentifiers { get; }
Property Value
| Type |
Description |
| System.Collections.Generic.IReadOnlyList<PrereleaseIdentifier> |
The prerelease identifiers for this version or empty if this is a release version.
|
SortOrderComparer
An
System.Collections.Generic.IEqualityComparer`1 and
System.Collections.Generic.IComparer`1
that compares
SemVersion by sort order. This can be used for sorting,
binary search, and using
SemVersion as a dictionary key.
Declaration
public static ISemVersionComparer SortOrderComparer { get; }
Property Value
| Type |
Description |
| ISemVersionComparer |
A sort order comparer that implements System.Collections.Generic.IEqualityComparer`1 and
System.Collections.Generic.IComparer`1 for SemVersion. |
Methods
ComparePrecedence(SemVersion, SemVersion)
Compares two versions and indicates whether the first precedes, follows, or is in the same
position as the second in the precedence order. Versions that differ only by build metadata
have the same precedence.
Declaration
public static int ComparePrecedence(SemVersion left, SemVersion right)
Parameters
Returns
| Type |
Description |
| System.Int32 |
An integer that indicates whether left precedes, follows, or is in the same
position as right in the precedence order.
| Value | Condition |
|---|
| -1 |
left precedes right in the precedence
order or left is null. | | 0 | left has the same precedence as right. | | 1 |
left follows right in the precedence order
or right is null.
|
|
ComparePrecedenceTo(SemVersion)
Compares two versions and indicates whether this instance precedes, follows, or is in the same
position as the other in the precedence order. Versions that differ only by build metadata
have the same precedence.
Declaration
public int ComparePrecedenceTo(SemVersion other)
Parameters
Returns
| Type |
Description |
| System.Int32 |
An integer that indicates whether this instance precedes, follows, or is in the same
position as other in the precedence order.
| Value | Condition |
|---|
| -1 | This instance precedes other in the precedence order. | | 0 | This instance has the same precedence as other. | | 1 |
This instance follows other in the precedence order
or other is null.
|
|
CompareSortOrder(SemVersion, SemVersion)
Compares two versions and indicates whether the first precedes, follows, or is equal to
the second in the sort order. Note that sort order is more specific than precedence order.
Declaration
public static int CompareSortOrder(SemVersion left, SemVersion right)
Parameters
Returns
| Type |
Description |
| System.Int32 |
An integer that indicates whether left precedes, follows, or is equal
to right in the sort order.
| Value | Condition |
|---|
| -1 |
left precedes right in the sort
order or left is null. | | 0 | left is equal to right. | | 1 |
left follows right in the sort order
or right is null.
|
|
CompareSortOrderTo(SemVersion)
Compares two versions and indicates whether this instance precedes, follows, or is equal
to the other in the sort order. Note that sort order is more specific than precedence order.
Declaration
public int CompareSortOrderTo(SemVersion other)
Parameters
Returns
| Type |
Description |
| System.Int32 |
An integer that indicates whether this instance precedes, follows, or is equal to the
other in the sort order.
| Value | Condition |
|---|
| -1 | This instance precedes the other in the sort order. | | 0 | This instance is equal to the other. | | 1 |
This instance follows the other in the sort order
or the other is null.
|
|
Equals(SemVersion)
Determines whether two semantic versions are equal.
Declaration
public bool Equals(SemVersion other)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if other is equal to this version;
otherwise false. |
Equals(SemVersion, SemVersion)
Determines whether two semantic versions are equal.
Declaration
public static bool Equals(SemVersion left, SemVersion right)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if the two versions are equal, otherwise false. |
Equals(Object)
Determines whether the given object is equal to this version.
Declaration
public override bool Equals(object obj)
Parameters
| Type |
Name |
Description |
| System.Object |
obj |
|
Returns
| Type |
Description |
| System.Boolean |
true if obj is equal to this version;
otherwise false. |
FromVersion(Version)
Converts a System.Version into the equivalent semantic version.
Declaration
public static SemVersion FromVersion(Version version)
Parameters
| Type |
Name |
Description |
| System.Version |
version |
The version to be converted to a semantic version. |
Returns
| Type |
Description |
| SemVersion |
The equivalent semantic version. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
version is null. |
| System.ArgumentException |
version has a revision number greater than zero. |
GetHashCode()
Gets 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)
Populates a System.Runtime.Serialization.SerializationInfo with the data needed to serialize the target object.
Declaration
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
| Type |
Name |
Description |
| System.Runtime.Serialization.SerializationInfo |
info |
The System.Runtime.Serialization.SerializationInfo to populate with data. |
| System.Runtime.Serialization.StreamingContext |
context |
The destination (see System.Runtime.Serialization.SerializationInfo) for this serialization. |
Parse(String, SemVersionStyles, Int32)
Converts the string representation of a semantic version to its
SemVersion equivalent.
Declaration
public static SemVersion Parse(string version, SemVersionStyles style, int maxLength = 1024)
Parameters
| Type |
Name |
Description |
| System.String |
version |
The version string. |
| SemVersionStyles |
style |
A bitwise combination of enumeration values that indicates the style
elements that can be present in version. The preferred value to use
is Strict. |
| System.Int32 |
maxLength |
The maximum length of version that should be
parsed. This prevents attacks using very long version strings. |
Returns
Exceptions
| Type |
Condition |
| System.ArgumentException |
style is not a valid
SemVersionStyles value. |
| System.ArgumentNullException |
version is null. |
| System.FormatException |
The version is invalid or not in a
format compliant with style. |
Parse(String, Int32)
Declaration
public static SemVersion Parse(string version, int maxLength = 1024)
Parameters
| Type |
Name |
Description |
| System.String |
version |
|
| System.Int32 |
maxLength |
|
Returns
ParsedFrom(BigInteger, Nullable<BigInteger>, Nullable<BigInteger>, String, String, Boolean)
Create a new instance of the
SemVersion class. Parses prerelease
and metadata identifiers from dot separated strings. If parsing is not needed, use a
constructor instead.
Declaration
public static SemVersion ParsedFrom(BigInteger major, Nullable<BigInteger> minor = null, Nullable<BigInteger> patch = null, string prerelease = "", string metadata = "", bool allowLeadingZeros = false)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The major version number. |
| System.Nullable<System.Numerics.BigInteger> |
minor |
The minor version number. |
| System.Nullable<System.Numerics.BigInteger> |
patch |
The patch version number. |
| System.String |
prerelease |
The prerelease portion (e.g. "alpha.5"). |
| System.String |
metadata |
The build metadata (e.g. "nightly.232"). |
| System.Boolean |
allowLeadingZeros |
Allow leading zeros in numeric prerelease identifiers. Leading
zeros will be removed. |
Returns
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major,
minor, or patch version number is negative. |
| System.ArgumentException |
A prerelease identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens) or has leading
zeros for a numeric identifier when allowLeadingZeros is
false. Or, a metadata identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens). |
PrecedenceEquals(SemVersion)
Determines whether two semantic versions have the same precedence. Versions that differ
only by build metadata have the same precedence.
Declaration
public bool PrecedenceEquals(SemVersion other)
Parameters
| Type |
Name |
Description |
| SemVersion |
other |
The semantic version to compare to. |
Returns
| Type |
Description |
| System.Boolean |
true if the version precedences are equal, otherwise
false. |
PrecedenceEquals(SemVersion, SemVersion)
Determines whether two semantic versions have the same precedence. Versions that differ
only by build metadata have the same precedence.
Declaration
public static bool PrecedenceEquals(SemVersion left, SemVersion right)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if the version precedences are equal, otherwise
false. |
Satisfies(SemVersionRange)
Checks if this version is contained in the given range.
Declaration
public bool Satisfies(SemVersionRange range)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if the version is contained in the range,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
range is
null. |
Satisfies(UnbrokenSemVersionRange)
Checks if this version is contained in the given unbroken range.
Declaration
public bool Satisfies(UnbrokenSemVersionRange range)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if the version is contained in the range,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
range is
null. |
Satisfies(Predicate<SemVersion>)
Checks if this version satisfies the given predicate.
Declaration
public bool Satisfies(Predicate<SemVersion> predicate)
Parameters
| Type |
Name |
Description |
| System.Predicate<SemVersion> |
predicate |
The predicate to evaluate on this version. |
Returns
| Type |
Description |
| System.Boolean |
true if the version satisfies the predicate,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
predicate is
null. |
Satisfies(String, SemVersionRangeOptions, Int32)
Checks if this version is contained in the given range.
Declaration
public bool Satisfies(string range, SemVersionRangeOptions options, int maxLength = 2048)
Parameters
| Type |
Name |
Description |
| System.String |
range |
The range to parse and evaluate. |
| SemVersionRangeOptions |
options |
A bitwise combination of enumeration values that indicates the style
elements that can be present in range. The overload without this
parameter defaults to Strict. |
| System.Int32 |
maxLength |
The maximum length of range that should be
parsed. This prevents attacks using very long range strings. |
Returns
| Type |
Description |
| System.Boolean |
true if the version is contained in the range,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
range is
null. |
| System.ArgumentException |
options is not a valid
SemVersionRangeOptions value. |
| System.ArgumentOutOfRangeException |
maxLength is less than
zero. |
| System.FormatException |
The range is invalid or not in a
format compliant with options. |
Satisfies(String, Int32)
Checks if this version is contained in the given range. The range is parsed using
Strict.
Declaration
public bool Satisfies(string range, int maxLength = 2048)
Parameters
| Type |
Name |
Description |
| System.String |
range |
The range to parse and evaluate. |
| System.Int32 |
maxLength |
The maximum length of range that should be
parsed. This prevents attacks using very long range strings. |
Returns
| Type |
Description |
| System.Boolean |
true if the version is contained in the range,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
range is
null. |
| System.ArgumentOutOfRangeException |
maxLength is less than
zero. |
| System.FormatException |
The range is invalid or not in a
format compliant with Strict. |
SatisfiesNpm(String, Boolean, Int32)
Checks if this version is contained in the given range in npm format.
Declaration
public bool SatisfiesNpm(string range, bool includeAllPrerelease, int maxLength = 2048)
Parameters
| Type |
Name |
Description |
| System.String |
range |
The npm format range to parse and evaluate. |
| System.Boolean |
includeAllPrerelease |
Whether to include all prerelease versions satisfying
the bounds in the range or to only include prerelease versions when it matches a bound
that explicitly includes prerelease versions. |
| System.Int32 |
maxLength |
The maximum length of range that should be
parsed. This prevents attacks using very long range strings. |
Returns
| Type |
Description |
| System.Boolean |
true if the version is contained in the range,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
range is
null. |
| System.ArgumentOutOfRangeException |
maxLength is less than
zero. |
| System.FormatException |
The range is invalid. |
SatisfiesNpm(String, Int32)
Checks if this version is contained in the given range in npm format. Does not include
all prerelease when parsing the range.
Declaration
public bool SatisfiesNpm(string range, int maxLength = 2048)
Parameters
| Type |
Name |
Description |
| System.String |
range |
The npm format range to parse and evaluate. |
| System.Int32 |
maxLength |
The maximum length of range that should be
parsed. This prevents attacks using very long range strings. |
Returns
| Type |
Description |
| System.Boolean |
true if the version is contained in the range,
otherwise false. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
range is
null. |
| System.ArgumentOutOfRangeException |
maxLength is less than
zero. |
| System.FormatException |
The range is invalid. |
ToString()
Converts this version to an equivalent string value.
Declaration
public override string ToString()
Returns
| Type |
Description |
| System.String |
The System.String equivalent of this version.
|
ToVersion()
Converts this semantic version to a System.Version.
Declaration
public Version ToVersion()
Returns
| Type |
Description |
| System.Version |
The equivalent System.Version. |
Exceptions
| Type |
Condition |
| System.InvalidOperationException |
The semantic version is a prerelease version
or has build metadata or has a major, minor, or patch version number greater than
System.Int32.MaxValue. |
TryParse(String, out SemVersion, Int32)
Declaration
public static bool TryParse(string version, out SemVersion semver, int maxLength = 1024)
Parameters
| Type |
Name |
Description |
| System.String |
version |
|
| SemVersion |
semver |
|
| System.Int32 |
maxLength |
|
Returns
| Type |
Description |
| System.Boolean |
|
TryParse(String, SemVersionStyles, out SemVersion, Int32)
Converts the string representation of a semantic version to its
SemVersion
equivalent. The return value indicates whether the conversion succeeded.
Declaration
public static bool TryParse(string version, SemVersionStyles style, out SemVersion semver, int maxLength = 1024)
Parameters
| Type |
Name |
Description |
| System.String |
version |
The version string. |
| SemVersionStyles |
style |
A bitwise combination of enumeration values that indicates the style
elements that can be present in version. The preferred value to use
is Strict. |
| SemVersion |
semver |
When this method returns, contains a SemVersion instance equivalent
to the version string passed in, if the version string was valid, or null if the
version string was invalid. |
| System.Int32 |
maxLength |
The maximum length of version that should be
parsed. This prevents attacks using very long version strings. |
Returns
| Type |
Description |
| System.Boolean |
false when an invalid version string is passed, otherwise true. |
Exceptions
| Type |
Condition |
| System.ArgumentException |
style is not a valid
SemVersionStyles value. |
Creates a copy of the current instance with multiple changed properties. If changing only
one property use one of the more specific WithX() methods.
Declaration
public SemVersion With(Nullable<BigInteger> major = null, Nullable<BigInteger> minor = null, Nullable<BigInteger> patch = null, IEnumerable<PrereleaseIdentifier> prerelease = null, IEnumerable<MetadataIdentifier> metadata = null)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Numerics.BigInteger> |
major |
The value to replace the major version number or null to leave it unchanged. |
| System.Nullable<System.Numerics.BigInteger> |
minor |
The value to replace the minor version number or null to leave it unchanged. |
| System.Nullable<System.Numerics.BigInteger> |
patch |
The value to replace the patch version number or null to leave it unchanged. |
| System.Collections.Generic.IEnumerable<PrereleaseIdentifier> |
prerelease |
The value to replace the prerelease identifiers or null to leave it unchanged. |
| System.Collections.Generic.IEnumerable<MetadataIdentifier> |
metadata |
The value to replace the build metadata identifiers or null to leave it unchanged. |
Returns
| Type |
Description |
| SemVersion |
The new version with changed properties. |
To change the minor and patch versions:
var modifiedVersion = version.With(minor: 2, patch: 4);
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major,
minor, or patch version number is negative. |
| System.ArgumentException |
A prerelease or metadata identifier has the default value. |
WithMajor(BigInteger)
Creates a copy of the current instance with a different major version number.
Declaration
public SemVersion WithMajor(BigInteger major)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
major |
The value to replace the major version number. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different major version number. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
major is negative. |
Creates a copy of the current instance with different build metadata identifiers.
Declaration
public SemVersion WithMetadata(MetadataIdentifier metadataIdentifier, params MetadataIdentifier[] metadataIdentifiers)
Parameters
| Type |
Name |
Description |
| MetadataIdentifier |
metadataIdentifier |
The first identifier to replace the existing
build metadata identifiers. |
| MetadataIdentifier[] |
metadataIdentifiers |
The rest of the identifiers to replace the
existing build metadata identifiers. |
Returns
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
metadataIdentifiers is
null. |
| System.ArgumentException |
A metadata identifier has the default value. |
Creates a copy of the current instance with different build metadata identifiers.
Declaration
public SemVersion WithMetadata(IEnumerable<MetadataIdentifier> metadataIdentifiers)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<MetadataIdentifier> |
metadataIdentifiers |
The identifiers to replace the build metadata identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different build metadata identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
metadataIdentifiers is
null. |
| System.ArgumentException |
A metadata identifier has the default value. |
Creates a copy of the current instance with different build metadata identifiers.
Declaration
public SemVersion WithMetadata(IEnumerable<string> metadataIdentifiers)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<System.String> |
metadataIdentifiers |
The identifiers to replace the build metadata identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different build metadata identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
metadataIdentifiers is
null or one of the metadata identifiers is null. |
| System.ArgumentException |
A metadata identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens). |
Creates a copy of the current instance with different build metadata identifiers.
Declaration
public SemVersion WithMetadata(string metadataIdentifier, params string[] metadataIdentifiers)
Parameters
| Type |
Name |
Description |
| System.String |
metadataIdentifier |
The first identifier to replace the existing
build metadata identifiers. |
| System.String[] |
metadataIdentifiers |
The rest of the build metadata identifiers to replace the
existing build metadata identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different build metadata identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
metadataIdentifier or
metadataIdentifiers is null or one of the metadata
identifiers is null. |
| System.ArgumentException |
A metadata identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens). |
Creates a copy of the current instance with different build metadata.
Declaration
public SemVersion WithMetadataParsedFrom(string metadata)
Parameters
| Type |
Name |
Description |
| System.String |
metadata |
The value to replace the build metadata. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different build metadata. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
metadata is null. |
| System.ArgumentException |
A metadata identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens). |
WithMinor(BigInteger)
Creates a copy of the current instance with a different minor version number.
Declaration
public SemVersion WithMinor(BigInteger minor)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
minor |
The value to replace the minor version number. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different minor version number. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
minor is negative. |
Creates a copy of the current instance without build metadata.
Declaration
public SemVersion WithoutMetadata()
Returns
| Type |
Description |
| SemVersion |
The new version without build metadata. |
WithoutPrerelease()
Creates a copy of the current instance without prerelease identifiers.
Declaration
public SemVersion WithoutPrerelease()
Returns
| Type |
Description |
| SemVersion |
The new version without prerelease identifiers. |
Creates a copy of the current instance without prerelease identifiers or build metadata.
Declaration
public SemVersion WithoutPrereleaseOrMetadata()
Returns
| Type |
Description |
| SemVersion |
The new version without prerelease identifiers or build metadata. |
WithParsedFrom(Nullable<BigInteger>, Nullable<BigInteger>, Nullable<BigInteger>, String, String, Boolean)
Declaration
public SemVersion WithParsedFrom(Nullable<BigInteger> major = null, Nullable<BigInteger> minor = null, Nullable<BigInteger> patch = null, string prerelease = null, string metadata = null, bool allowLeadingZeros = false)
Parameters
| Type |
Name |
Description |
| System.Nullable<System.Numerics.BigInteger> |
major |
The value to replace the major version number or null to leave it unchanged. |
| System.Nullable<System.Numerics.BigInteger> |
minor |
The value to replace the minor version number or null to leave it unchanged. |
| System.Nullable<System.Numerics.BigInteger> |
patch |
The value to replace the patch version number or null to leave it unchanged. |
| System.String |
prerelease |
The value to replace the prerelease identifiers or null to leave it unchanged. |
| System.String |
metadata |
The value to replace the build metadata identifiers or null to leave it unchanged. |
| System.Boolean |
allowLeadingZeros |
Allow leading zeros in numeric prerelease identifiers. Leading
zeros will be removed. |
Returns
| Type |
Description |
| SemVersion |
The new version with changed properties. |
Examples
To change the patch version and prerelease identifiers version:
var modifiedVersion = version.WithParsedFrom(patch: 4, prerelease: "alpha.5");
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
The major,
minor, or patch version number is negative. |
| System.ArgumentException |
A prerelease identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens) or has leading
zeros for a numeric identifier when allowLeadingZeros is
false. Or, a metadata identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens). |
WithPatch(BigInteger)
Creates a copy of the current instance with a different patch version number.
Declaration
public SemVersion WithPatch(BigInteger patch)
Parameters
| Type |
Name |
Description |
| System.Numerics.BigInteger |
patch |
The value to replace the patch version number. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different patch version number. |
Exceptions
| Type |
Condition |
| System.ArgumentOutOfRangeException |
patch is negative. |
WithPrerelease(PrereleaseIdentifier, PrereleaseIdentifier[])
Creates a copy of the current instance with different prerelease identifiers.
Declaration
public SemVersion WithPrerelease(PrereleaseIdentifier prereleaseIdentifier, params PrereleaseIdentifier[] prereleaseIdentifiers)
Parameters
| Type |
Name |
Description |
| PrereleaseIdentifier |
prereleaseIdentifier |
The first identifier to replace the existing
prerelease identifiers. |
| PrereleaseIdentifier[] |
prereleaseIdentifiers |
The rest of the identifiers to replace the
existing prerelease identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different prerelease identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
prereleaseIdentifiers is
null. |
| System.ArgumentException |
A prerelease identifier has the default value. |
WithPrerelease(IEnumerable<PrereleaseIdentifier>)
Creates a copy of the current instance with different prerelease identifiers.
Declaration
public SemVersion WithPrerelease(IEnumerable<PrereleaseIdentifier> prereleaseIdentifiers)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<PrereleaseIdentifier> |
prereleaseIdentifiers |
The identifiers to replace the prerelease identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different prerelease identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
prereleaseIdentifiers is null. |
| System.ArgumentException |
A prerelease identifier has the default value. |
WithPrerelease(IEnumerable<String>)
Creates a copy of the current instance with different prerelease identifiers.
Declaration
public SemVersion WithPrerelease(IEnumerable<string> prereleaseIdentifiers)
Parameters
| Type |
Name |
Description |
| System.Collections.Generic.IEnumerable<System.String> |
prereleaseIdentifiers |
The identifiers to replace the prerelease identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different prerelease identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
prereleaseIdentifiers is
null or one of the prerelease identifiers is null. |
| System.ArgumentException |
A prerelease identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens) or has leading
zeros for a numeric identifier. |
WithPrerelease(String, String[])
Creates a copy of the current instance with different prerelease identifiers.
Declaration
public SemVersion WithPrerelease(string prereleaseIdentifier, params string[] prereleaseIdentifiers)
Parameters
| Type |
Name |
Description |
| System.String |
prereleaseIdentifier |
The first identifier to replace the existing
prerelease identifiers. |
| System.String[] |
prereleaseIdentifiers |
The rest of the identifiers to replace the
existing prerelease identifiers. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different prerelease identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
prereleaseIdentifier or
prereleaseIdentifiers is null or one of the
prerelease identifiers is null. |
| System.ArgumentException |
A prerelease identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens) or has leading
zeros for a numeric identifier. |
WithPrereleaseParsedFrom(String, Boolean)
Creates a copy of the current instance with a different prerelease portion.
Declaration
public SemVersion WithPrereleaseParsedFrom(string prerelease, bool allowLeadingZeros = false)
Parameters
| Type |
Name |
Description |
| System.String |
prerelease |
The value to replace the prerelease portion. |
| System.Boolean |
allowLeadingZeros |
Whether to allow leading zeros in the prerelease identifiers.
If true, leading zeros will be allowed on numeric identifiers
but will be removed. |
Returns
| Type |
Description |
| SemVersion |
The new version with the different prerelease identifiers. |
Exceptions
| Type |
Condition |
| System.ArgumentNullException |
prerelease is null. |
| System.ArgumentException |
A prerelease identifier is empty or contains invalid
characters (i.e. characters that are not ASCII alphanumerics or hyphens) or has leading
zeros for a numeric identifier when allowLeadingZeros is false. |
Operators
Equality(SemVersion, SemVersion)
Determines whether two semantic versions are equal.
Declaration
public static bool operator ==(SemVersion left, SemVersion right)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if the two versions are equal, otherwise false. |
Inequality(SemVersion, SemVersion)
Determines whether two semantic versions are not equal.
Declaration
public static bool operator !=(SemVersion left, SemVersion right)
Parameters
Returns
| Type |
Description |
| System.Boolean |
true if the two versions are not equal, otherwise false. |
Implements
System.IEquatable<>
System.Runtime.Serialization.ISerializable