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.IEnumerable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
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
Declaration
public int Count { get; }
Property Value
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]
Declaration
public UnbrokenSemVersionRange this[int index] { get; }
Parameters
Property Value
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
Returns
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
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
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()
Declaration
public IEnumerator<UnbrokenSemVersionRange> GetEnumerator()
Returns
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)
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
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)
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
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)
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
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)
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
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()
Declaration
public override string ToString()
Returns
Overrides
System.Object.ToString()
TryParse(String, out SemVersionRange, Int32)
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)
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)
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. |
Exceptions
Type |
Condition |
System.ArgumentOutOfRangeException |
maxLength is less than zero. |
TryParseNpm(String, Boolean, out SemVersionRange, Int32)
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. |
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
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
Returns
Type |
Description |
System.Boolean |
true if the two ranges are not equal, otherwise false. |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
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>