Show / Hide Table of Contents

Struct PrereleaseIdentifier

An individual prerelease identifier for a semantic version.
Implements
System.IEquatable<PrereleaseIdentifier>
System.IComparable<PrereleaseIdentifier>
System.IComparable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
Namespace: Semver
Assembly: Semver.dll
Syntax
public readonly struct PrereleaseIdentifier : IEquatable<PrereleaseIdentifier>, IComparable<PrereleaseIdentifier>, IComparable
Remarks

The prerelease portion of a semantic version is composed of dot ('.') separated identifiers. A prerelease identifier is either an alphanumeric or numeric identifier. A valid numeric identifier is composed of ASCII digits ([0-9]) without leading zeros. A valid alphanumeric identifier is a non-empty string of ASCII alphanumeric and hyphen characters ([0-9A-Za-z-]) with at least one non-digit character. Prerelease identifiers are compared first by whether they are numeric or alphanumeric. Numeric identifiers have lower precedence than alphanumeric identifiers. Numeric identifiers are compared to each other numerically. Alphanumeric identifiers are compared to each other lexically in ASCII sort order.

Because PrereleaseIdentifier is a struct, the default value is a PrereleaseIdentifier with a null value. However, the Semver namespace types do not accept and will not return such a PrereleaseIdentifier.

Invalid prerelease identifiers including arbitrary Unicode characters, empty string, and numeric identifiers with leading zero can currently be produced by the SemVersion(Int32, Int32, Int32, String, String) constructor and the obsolete Parse(String, Boolean) and TryParse(String, out SemVersion, Boolean) methods. Such alphanumeric identifiers are compared via an ordinal string comparision. Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015').

Constructors

PrereleaseIdentifier(Int32)

Construct a valid numeric PrereleaseIdentifier from an integer value.
Declaration
public PrereleaseIdentifier(int value)
Parameters
Type Name Description
System.Int32 value The non-negative value of this identifier.
Exceptions
Type Condition
System.ArgumentOutOfRangeException The value is negative.

PrereleaseIdentifier(String, Boolean)

Constructs a valid PrereleaseIdentifier.
Declaration
public PrereleaseIdentifier(string value, bool allowLeadingZeros = false)
Parameters
Type Name Description
System.String value The string value of this prerelease identifier.
System.Boolean allowLeadingZeros Whether to allow leading zeros in the value parameter. If true, leading zeros will be allowed on numeric identifiers but will be removed.
Remarks
Because a valid numeric identifier does not have leading zeros, this constructor will never create a PrereleaseIdentifier with leading zeros even if allowLeadingZeros is true. Any leading zeros will be removed.
Exceptions
Type Condition
System.ArgumentNullException The value is null.
System.ArgumentException The value 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.
System.OverflowException The numeric identifier value is too large for System.Int32.

Properties

NumericValue

The numeric value of the prerelease identifier if it is a numeric identifier, otherwise null.
Declaration
public readonly int? NumericValue { get; }
Property Value
Type Description
System.Nullable<System.Int32> The numeric value of the prerelease identifier if it is a numeric identifier, otherwise null.
Remarks
The numeric value of a prerelease identifier will never be negative.

Value

The string value of the prerelease identifier even if it is a numeric identifier.
Declaration
public readonly string Value { get; }
Property Value
Type Description
System.String The string value of this prerelease identifier even if it is a numeric identifier or null if this is a default PrereleaseIdentifier.
Remarks
Invalid numeric prerelease identifiers with leading zeros will have a string value including the leading zeros. This can be used to distinguish invalid numeric identifiers with different numbers of leading zeros.

Methods

CompareTo(PrereleaseIdentifier)

Compares two identifiers and indicates whether this instance precedes, follows, or is equal to the other in precedence order.
Declaration
public readonly int CompareTo(PrereleaseIdentifier value)
Parameters
Type Name Description
PrereleaseIdentifier value
Returns
Type Description
System.Int32 An integer that indicates whether this instance precedes, follows, or is equal to value in precedence order.
ValueCondition
-1This instance precedes value.
0This instance is equal to value.
1This instance follows value.
Remarks
Numeric identifiers have lower precedence than alphanumeric identifiers. Numeric identifiers are compared numerically. Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015'). Alphanumeric identifiers are compared lexically in ASCII sort order. Invalid alphanumeric identifiers are compared via an ordinal string comparision.

CompareTo(Object)

Compares this identifier to an System.Object and indicates whether this instance precedes, follows, or is equal to the object in precedence order.
Declaration
public readonly int CompareTo(object value)
Parameters
Type Name Description
System.Object value
Returns
Type Description
System.Int32 An integer that indicates whether this instance precedes, follows, or is equal to value in precedence order.
ValueCondition
-1This instance precedes value.
0This instance is equal to value.
1This instance follows value or value is null.
Remarks
Numeric identifiers have lower precedence than alphanumeric identifiers. Numeric identifiers are compared numerically. Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015'). Alphanumeric identifiers are compared lexically in ASCII sort order. Invalid alphanumeric identifiers are compared via an ordinal string comparision.
Exceptions
Type Condition
System.ArgumentException value is not a PrereleaseIdentifier.

Equals(PrereleaseIdentifier)

Determines whether two identifiers are equal.
Declaration
public readonly bool Equals(PrereleaseIdentifier value)
Parameters
Type Name Description
PrereleaseIdentifier value
Returns
Type Description
System.Boolean true if value is equal to the this identifier; otherwise false.
Remarks
Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015').

Equals(Object)

Determines whether the given object is equal to this identifier.
Declaration
public override readonly bool Equals(object value)
Parameters
Type Name Description
System.Object value
Returns
Type Description
System.Boolean true if value is equal to the this identifier; otherwise false.
Overrides
System.ValueType.Equals(System.Object)
Remarks
Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015').

GetHashCode()

Gets a hash code for this identifier.
Declaration
public override readonly int GetHashCode()
Returns
Type Description
System.Int32 A hash code for this identifier.
Overrides
System.ValueType.GetHashCode()
Remarks
Numeric identifiers with leading zeros are have the same hash code (e.g. '15' has the same hash code as '015').

ToString()

Converts this identifier into an equivalent string value.
Declaration
public override readonly string ToString()
Returns
Type Description
System.String The string value of this identifier or null if this is a default PrereleaseIdentifier
Overrides
System.ValueType.ToString()

Operators

Equality(PrereleaseIdentifier, PrereleaseIdentifier)

Determines whether two identifiers are equal.
Declaration
public static bool operator ==(PrereleaseIdentifier left, PrereleaseIdentifier right)
Parameters
Type Name Description
PrereleaseIdentifier left
PrereleaseIdentifier right
Returns
Type Description
System.Boolean true if the value of left is the same as the value of right; otherwise false.
Remarks
Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015').

Implicit(PrereleaseIdentifier to String)

Converts this identifier into an equivalent string value.
Declaration
public static implicit operator string (PrereleaseIdentifier prereleaseIdentifier)
Parameters
Type Name Description
PrereleaseIdentifier prereleaseIdentifier
Returns
Type Description
System.String The string value of this identifier or null if this is a default PrereleaseIdentifier

Inequality(PrereleaseIdentifier, PrereleaseIdentifier)

Determines whether two identifiers are not equal.
Declaration
public static bool operator !=(PrereleaseIdentifier left, PrereleaseIdentifier right)
Parameters
Type Name Description
PrereleaseIdentifier left
PrereleaseIdentifier right
Returns
Type Description
System.Boolean true if the value of left is different from the value of right; otherwise false.
Remarks
Numeric identifiers with leading zeros are considered equal (e.g. '15' is equal to '015').

Implements

System.IEquatable<T>
System.IComparable<T>
System.IComparable
In This Article
Back to top Generated by DocFX