Show / Hide Table of Contents

Class SemVersionRange

A range of SemVersion values. A range can have gaps in it and may include only some prerelease versions between included release versions. For a range that cannot have gaps see the UnbrokenSemVersionRange class.
Inheritance
System.Object
SemVersionRange
Implements
System.Collections.Generic.IReadOnlyList<UnbrokenSemVersionRange>
System.Collections.Generic.IReadOnlyCollection<UnbrokenSemVersionRange>
System.Collections.Generic.IEnumerable<UnbrokenSemVersionRange>
System.Collections.IEnumerable
System.IEquatable<SemVersionRange>
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Semver
Assembly: Semver.dll
Syntax
public sealed class SemVersionRange : IReadOnlyList<UnbrokenSemVersionRange>, IReadOnlyCollection<UnbrokenSemVersionRange>, IEnumerable<UnbrokenSemVersionRange>, IEnumerable, IEquatable<SemVersionRange>

Properties

All

The range that contains both all release and prerelease versions.
Declaration
public static SemVersionRange All { get; }
Property Value
Type Description
SemVersionRange The range that contains both all release and prerelease versions.

AllRelease

The range that contains all release versions but no prerelease versions.
Declaration
public static SemVersionRange AllRelease { get; }
Property Value
Type Description
SemVersionRange The range that contains all release versions but no prerelease versions.

Count

The number of UnbrokenSemVersionRanges that make up this range.
Declaration
public int Count { get; }
Property Value
Type Description
System.Int32 The number of UnbrokenSemVersionRanges that make up this range.

Empty

The empty range that contains no versions.
Declaration
public static SemVersionRange Empty { get; }
Property Value
Type Description
SemVersionRange The empty range that contains no versions.

Item[Int32]

Get the UnbrokenSemVersionRange making up this range at the given index.
Declaration
public UnbrokenSemVersionRange this[int index] { get; }
Parameters
Type Name Description
System.Int32 index The zero-based index of the UnbrokenSemVersionRange to get.
Property Value
Type Description
UnbrokenSemVersionRange The UnbrokenSemVersionRange making up this range at the given index.

Methods

AtLeast(SemVersion, Boolean)

Construct a range containing versions equal to or greater than the given version.
Declaration
public static SemVersionRange AtLeast(SemVersion version, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion version The range will contain all versions greater than or equal to this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given version if it is prerelease.
Returns
Type Description
SemVersionRange A range containing versions greater than or equal to the given version.

AtMost(SemVersion, Boolean)

Construct a range containing versions equal to or less than the given version.
Declaration
public static SemVersionRange AtMost(SemVersion version, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion version The range will contain all versions less than or equal to this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given version if it is prerelease.
Returns
Type Description
SemVersionRange A range containing versions less than or equal to the given version.

Contains(SemVersion)

Determine whether this range contains the given version.
Declaration
public bool Contains(SemVersion version)
Parameters
Type Name Description
SemVersion version The version to test against the range.
Returns
Type Description
System.Boolean true if the version is contained in the range, otherwise false.

Create(UnbrokenSemVersionRange[])

Construct a range that joins the given UnbrokenSemVersionRanges. It will contain all versions contained by any of the given unbroken ranges.
Declaration
public static SemVersionRange Create(params UnbrokenSemVersionRange[] ranges)
Parameters
Type Name Description
UnbrokenSemVersionRange[] ranges The unbroken ranges to join into a single range.
Returns
Type Description
SemVersionRange A range that joins the given UnbrokenSemVersionRanges. It will contain all versions contained by any of the given unbroken ranges.
Remarks
The unbroken ranges are simplified and sorted. So, the resulting SemVersionRange may not contain the same number of UnbrokenSemVersionRanges in the same order as passed to this method.

Create(IEnumerable<UnbrokenSemVersionRange>)

Construct a range that joins the given UnbrokenSemVersionRanges. It will contain all versions contained by any of the given unbroken ranges.
Declaration
public static SemVersionRange Create(IEnumerable<UnbrokenSemVersionRange> ranges)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<UnbrokenSemVersionRange> ranges The unbroken ranges to join into a single range.
Returns
Type Description
SemVersionRange A range that joins the given UnbrokenSemVersionRanges. It will contain all versions contained by any of the given unbroken ranges.
Remarks
The unbroken ranges are simplified and sorted. So, the resulting SemVersionRange may not contain the same number of UnbrokenSemVersionRanges in the same order as passed to this method.

Equals(SemVersion)

Construct a range containing only a single version.
Declaration
public static SemVersionRange Equals(SemVersion version)
Parameters
Type Name Description
SemVersion version The version the range should contain.
Returns
Type Description
SemVersionRange A range containing only the given version.

Equals(SemVersionRange)

Determines whether two version ranges are equal. Due to the complexity of ranges, it may be possible for two ranges to match the same set of versions but be expressed in different ways and so not be equal.
Declaration
public bool Equals(SemVersionRange other)
Parameters
Type Name Description
SemVersionRange other
Returns
Type Description
System.Boolean true if other is equal to the this range; otherwise false.

Equals(Object)

Determines whether the given object is equal to this range. Due to the complexity of ranges, it may be possible for two ranges to match the same set of versions but be expressed in different ways and so not be equal.
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 the this range; otherwise false.
Overrides
System.Object.Equals(System.Object)

Exclusive(SemVersion, SemVersion, Boolean)

Construct a range containing all versions between the given versions excluding those versions.
Declaration
public static SemVersionRange Exclusive(SemVersion start, SemVersion end, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion start The range will contain only versions greater than this.
SemVersion end The range will contain only versions less than this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given versions if they are prerelease.
Returns
Type Description
SemVersionRange A range containing versions between the given versions including the end but not the start.

GetEnumerator()

Get an enumerator that iterates through the UnbrokenSemVersionRanges making up this range.
Declaration
public IEnumerator<UnbrokenSemVersionRange> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<UnbrokenSemVersionRange> An enumerator that iterates through the UnbrokenSemVersionRanges making up this range.

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.
Overrides
System.Object.GetHashCode()

GreaterThan(SemVersion, Boolean)

Construct a range containing versions greater than the given version.
Declaration
public static SemVersionRange GreaterThan(SemVersion version, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion version The range will contain all versions greater than this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given version if it is prerelease.
Returns
Type Description
SemVersionRange A range containing versions greater than the given version.

Inclusive(SemVersion, SemVersion, Boolean)

Construct a range containing all versions between the given versions including those versions.
Declaration
public static SemVersionRange Inclusive(SemVersion start, SemVersion end, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion start The range will contain only versions greater than or equal to this.
SemVersion end The range will contain only versions less than or equal to this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given versions if they are prerelease.
Returns
Type Description
SemVersionRange A range containing versions between the given versions including those versions.

InclusiveOfEnd(SemVersion, SemVersion, Boolean)

Construct a range containing all versions between the given versions including the end but not the start.
Declaration
public static SemVersionRange InclusiveOfEnd(SemVersion start, SemVersion end, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion start The range will contain only versions greater than this.
SemVersion end The range will contain only versions less than or equal to this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given versions if they are prerelease.
Returns
Type Description
SemVersionRange A range containing versions between the given versions including the end but not the start.

InclusiveOfStart(SemVersion, SemVersion, Boolean)

Construct a range containing all versions between the given versions including the start but not the end.
Declaration
public static SemVersionRange InclusiveOfStart(SemVersion start, SemVersion end, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion start The range will contain only versions greater than or equal to this.
SemVersion end The range will contain only versions less than this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given versions if they are prerelease.
Returns
Type Description
SemVersionRange A range containing versions between the given versions including the start but not the end.

LessThan(SemVersion, Boolean)

Construct a range containing versions less than the given version.
Declaration
public static SemVersionRange LessThan(SemVersion version, bool includeAllPrerelease = false)
Parameters
Type Name Description
SemVersion version The range will contain all versions less than this.
System.Boolean includeAllPrerelease Include all prerelease versions in the range rather than just those matching the given version if it is prerelease.
Returns
Type Description
SemVersionRange A range containing versions less than the given version.

Parse(String, SemVersionRangeOptions, Int32)

Convert a version range string in the standard range syntax into a SemVersionRange using the given options.
Declaration
public static SemVersionRange Parse(string range, SemVersionRangeOptions options, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the standard range syntax.
SemVersionRangeOptions options A bitwise combination of enumeration values that indicates the style elements that can be present in range and the options to use when constructing the range.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
SemVersionRange
Exceptions
Type Condition
System.ArgumentException options is not a valid SemVersionRangeOptions value.
System.ArgumentOutOfRangeException maxLength is less than zero.
System.ArgumentNullException range is null.
System.FormatException The range is invalid or not in a format compliant with options.
System.OverflowException A numeric part of a version in range is too large for an System.Int32.

Parse(String, Int32)

Convert a version range string in the standard range syntax into a SemVersionRange using the Strict option.
Declaration
public static SemVersionRange Parse(string range, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the standard range syntax.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
SemVersionRange
Exceptions
Type Condition
System.ArgumentOutOfRangeException maxLength is less than zero.
System.ArgumentNullException range is null.
System.FormatException The range is invalid or not in a format compliant with the Strict option.
System.OverflowException A numeric part of a version in range is too large for an System.Int32.

ParseNpm(String, Boolean, Int32)

Convert a version range string in the npm syntax into a SemVersionRange.
Declaration
public static SemVersionRange ParseNpm(string range, bool includeAllPrerelease, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the npm syntax.
System.Boolean includeAllPrerelease Whether to include all prerelease versions in the range rather than just prerelease versions matching a prerelease identifier in the range.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
SemVersionRange
Remarks
The npm "loose" option is not supported. The Parse(String, SemVersionRangeOptions, Int32) method provides more control over parsing. However, it does not accept all of the npm syntax.
Exceptions
Type Condition
System.ArgumentOutOfRangeException maxLength is less than zero.
System.ArgumentNullException range is null.
System.FormatException The range is invalid.
System.OverflowException A numeric part of a version in range is too large for an System.Int32.

ParseNpm(String, Int32)

Convert a version range string in the npm syntax into a SemVersionRange.
Declaration
public static SemVersionRange ParseNpm(string range, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the npm syntax.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
SemVersionRange
Remarks
The npm "loose" option is not supported. The Parse(String, SemVersionRangeOptions, Int32) method provides more control over parsing. However, it does not accept all of the npm syntax.
Exceptions
Type Condition
System.ArgumentOutOfRangeException maxLength is less than zero.
System.ArgumentNullException range is null.
System.FormatException The range is invalid.
System.OverflowException A numeric part of a version in range is too large for an System.Int32.

ToString()

Converts this version range to an equivalent string value in standard range syntax.
Declaration
public override string ToString()
Returns
Type Description
System.String The System.String equivalent of this version in standard range syntax.
Overrides
System.Object.ToString()
Remarks
Because version ranges are simplified and sorted, this method may return a different, but equivalent, range string from the originally parsed one. Ranges including all prerelease versions are indicated with the idiom of prefixing each comparison group with "*-*". This includes all prerelease versions because it matches all prerelease versions.

TryParse(String, out SemVersionRange, Int32)

Convert a version range string in the standard range syntax into a SemVersionRange using the Strict option.
Declaration
public static bool TryParse(string range, out SemVersionRange semverRange, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the standard range syntax.
SemVersionRange semverRange The converted SemVersionRange.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
System.Boolean false when an invalid version range string is passed, otherwise true.
Exceptions
Type Condition
System.ArgumentOutOfRangeException maxLength is less than zero.

TryParse(String, SemVersionRangeOptions, out SemVersionRange, Int32)

Convert a version range string in the standard range syntax into a SemVersionRange using the given options.
Declaration
public static bool TryParse(string range, SemVersionRangeOptions options, out SemVersionRange semverRange, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the standard range syntax.
SemVersionRangeOptions options A bitwise combination of enumeration values that indicates the style elements that can be present in range and the options to use when constructing the range.
SemVersionRange semverRange The converted SemVersionRange.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
System.Boolean false when an invalid version range string is passed, otherwise true.
Exceptions
Type Condition
System.ArgumentException options is not a valid SemVersionRangeOptions value.
System.ArgumentOutOfRangeException maxLength is less than zero.

TryParseNpm(String, out SemVersionRange, Int32)

Convert a version range string in the npm syntax into a SemVersionRange.
Declaration
public static bool TryParseNpm(string range, out SemVersionRange semverRange, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the npm syntax.
SemVersionRange semverRange The converted SemVersionRange.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
System.Boolean false when an invalid version range string is passed, otherwise true.
Remarks
The npm "loose" option is not supported. The TryParse(String, SemVersionRangeOptions, out SemVersionRange, Int32) method provides more control over parsing. However, it does not accept all of the npm syntax.
Exceptions
Type Condition
System.ArgumentOutOfRangeException maxLength is less than zero.

TryParseNpm(String, Boolean, out SemVersionRange, Int32)

Convert a version range string in the npm syntax into a SemVersionRange.
Declaration
public static bool TryParseNpm(string range, bool includeAllPrerelease, out SemVersionRange semverRange, int maxLength = 2048)
Parameters
Type Name Description
System.String range The version range string to parse. Accepts the npm syntax.
System.Boolean includeAllPrerelease Whether to include all prerelease versions in the range rather than just prerelease versions matching a prerelease identifier in the range.
SemVersionRange semverRange The converted SemVersionRange.
System.Int32 maxLength The maximum length of range that should be parsed. This prevents attacks using very long version range strings.
Returns
Type Description
System.Boolean false when an invalid version range string is passed, otherwise true.
Remarks
The npm "loose" option is not supported. The TryParse(String, SemVersionRangeOptions, out SemVersionRange, Int32) method provides more control over parsing. However, it does not accept all of the npm syntax.
Exceptions
Type Condition
System.ArgumentOutOfRangeException maxLength is less than zero.

Operators

Equality(SemVersionRange, SemVersionRange)

Determines whether two version ranges are equal. Due to the complexity of ranges, it may be possible for two ranges to match the same set of versions but be expressed in different ways and so not be equal.
Declaration
public static bool operator ==(SemVersionRange left, SemVersionRange right)
Parameters
Type Name Description
SemVersionRange left
SemVersionRange right
Returns
Type Description
System.Boolean true if the two values are equal, otherwise false.

Implicit(SemVersionRange to Predicate<SemVersion>)

Convert this range into a predicate function indicating whether a version is contained in the range.
Declaration
public static implicit operator Predicate<SemVersion>(SemVersionRange range)
Parameters
Type Name Description
SemVersionRange range The range to convert into a predicate function.
Returns
Type Description
System.Predicate<SemVersion> A predicate that indicates whether a given version is contained in this range.

Inequality(SemVersionRange, SemVersionRange)

Determines whether two version ranges are not equal. Due to the complexity of ranges, it may be possible for two ranges to match the same set of versions but be expressed in different ways and so not be equal.
Declaration
public static bool operator !=(SemVersionRange left, SemVersionRange right)
Parameters
Type Name Description
SemVersionRange left
SemVersionRange right
Returns
Type Description
System.Boolean true if the two ranges are not equal, otherwise false.

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Get an enumerator that iterates through the UnbrokenSemVersionRanges making up this range.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator An enumerator that iterates through the UnbrokenSemVersionRanges making up this range.

Implements

System.Collections.Generic.IReadOnlyList<T>
System.Collections.Generic.IReadOnlyCollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
System.IEquatable<T>
In This Article
Back to top Generated by DocFX