Search Results for

    Class SemVersion

    A semantic version implementation. Conforms with v2.0.0 of http://semver.org

    Inheritance
    object
    SemVersion
    Implements
    IComparable<SemVersion>
    IComparable
    ISerializable
    Inherited Members
    object.GetType()
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    Namespace: Semver
    Assembly: RedLoader.dll
    Syntax
    public sealed class SemVersion : IComparable<SemVersion>, IComparable, ISerializable

    Constructors

    SemVersion(int, int, int, string, string)

    Constructs 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
    int major

    The major version.

    int minor

    The minor version.

    int patch

    The patch version.

    string prerelease

    The prerelease version (e.g. "alpha").

    string build

    The build metadata (e.g. "nightly.232").

    SemVersion(Version)

    Constructs a new instance of the SemVersion class from a Version.

    Declaration
    public SemVersion(Version version)
    Parameters
    Type Name Description
    Version version

    The Version that is used to initialize the Major, Minor, Patch and Build.

    Properties

    Build

    Gets the build metadata.

    Declaration
    public string Build { get; }
    Property Value
    Type Description
    string

    The build metadata. Empty string if there is no build metadata.

    Major

    Gets the major version.

    Declaration
    public int Major { get; }
    Property Value
    Type Description
    int

    The major version.

    Minor

    Gets the minor version.

    Declaration
    public int Minor { get; }
    Property Value
    Type Description
    int

    The minor version.

    Patch

    Gets the patch version.

    Declaration
    public int Patch { get; }
    Property Value
    Type Description
    int

    The patch version.

    Prerelease

    Gets the prerelease version.

    Declaration
    public string Prerelease { get; }
    Property Value
    Type Description
    string

    The prerelease version. Empty string if this is a release version.

    Methods

    Change(int?, int?, int?, string, string)

    Make a copy of the current instance with changed properties.

    Declaration
    public SemVersion Change(int? major = null, int? minor = null, int? patch = null, string prerelease = null, string build = null)
    Parameters
    Type Name Description
    int? major

    The value to replace the major version or null to leave it unchanged.

    int? minor

    The value to replace the minor version or null to leave it unchanged.

    int? patch

    The value to replace the patch version or null to leave it unchanged.

    string prerelease

    The value to replace the prerelease version or null to leave it unchanged.

    string build

    The value to replace the build metadata or null to leave it unchanged.

    Returns
    Type Description
    SemVersion

    The new version object.

    Remarks

    The change method is intended to be called using named argument syntax, passing only those fields to be changed.

    Examples

    To change only the patch version:

    version.Change(patch: 4)

    Compare(SemVersion, SemVersion)

    Compares the specified versions.

    Declaration
    public static int Compare(SemVersion versionA, SemVersion versionB)
    Parameters
    Type Name Description
    SemVersion versionA

    The first version to compare.

    SemVersion versionB

    The second version to compare.

    Returns
    Type Description
    int

    A signed number indicating the relative values of versionA and versionB.

    CompareByPrecedence(SemVersion)

    Compares two semantic versions by precedence as defined in the SemVer spec. Versions that differ only by build metadata have the same precedence.

    Declaration
    public int CompareByPrecedence(SemVersion other)
    Parameters
    Type Name Description
    SemVersion other

    The semantic version.

    Returns
    Type Description
    int

    A value that indicates the relative order of the objects being compared. The return value has these meanings: Less than zero: This instance precedes other in the sort order. Zero: This instance occurs in the same position in the sort order as other. Greater than zero: This instance follows other in the sort order.

    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
    int

    A value that indicates the relative order of the objects being compared. The return value has these meanings: Less than zero: This instance precedes other in the sort order. Zero: This instance occurs in the same position in the sort order as other. Greater than zero: This instance follows other in the sort order.

    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
    object obj

    An object to compare with this instance.

    Returns
    Type Description
    int

    A value that indicates the relative order of the objects being compared. The return value has these meanings: Less than zero: This instance precedes obj in the sort order. Zero: This instance occurs in the same position in the sort order as obj. Greater than zero: This instance follows obj in the sort order.

    Exceptions
    Type Condition
    InvalidCastException

    The obj is not a SemVersion.

    Equals(SemVersion, SemVersion)

    Checks whether two semantic versions are equal.

    Declaration
    public static bool Equals(SemVersion versionA, SemVersion versionB)
    Parameters
    Type Name Description
    SemVersion versionA

    The first version to compare.

    SemVersion versionB

    The second version to compare.

    Returns
    Type Description
    bool

    true if the two values are equal, otherwise false.

    Equals(object)

    Determines whether the specified object is equal to this instance.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The object to compare with this instance.

    Returns
    Type Description
    bool

    true if the specified object is equal to this instance, otherwise false.

    Overrides
    object.Equals(object)
    Exceptions
    Type Condition
    InvalidCastException

    The obj is not a SemVersion.

    GetHashCode()

    Returns a hash code for this instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

    Overrides
    object.GetHashCode()

    GetObjectData(SerializationInfo, StreamingContext)

    Populates a SerializationInfo with the data needed to serialize the target object.

    Declaration
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    Parameters
    Type Name Description
    SerializationInfo info

    The SerializationInfo to populate with data.

    StreamingContext context

    The destination (see SerializationInfo) for this serialization.

    Parse(string, bool)

    Converts the string representation of a semantic version to its SemVersion equivalent.

    Declaration
    public static SemVersion Parse(string version, bool strict = false)
    Parameters
    Type Name Description
    string version

    The version string.

    bool strict

    If set to true minor and patch version are required, otherwise they are optional.

    Returns
    Type Description
    SemVersion

    The SemVersion object.

    Exceptions
    Type Condition
    ArgumentNullException

    The version is null.

    ArgumentException

    The version has an invalid format.

    InvalidOperationException

    The version is missing Minor or Patch versions and strict is true.

    OverflowException

    The Major, Minor, or Patch versions are larger than

    int.MaxValue
    .

    PrecedenceMatches(SemVersion)

    Returns whether two semantic versions have the same precedence. Versions that differ only by build metadata have the same precedence.

    Declaration
    public bool PrecedenceMatches(SemVersion other)
    Parameters
    Type Name Description
    SemVersion other

    The semantic version to compare to.

    Returns
    Type Description
    bool

    true if the version precedences are equal.

    ToString()

    Returns the string equivalent of this version.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    The string equivalent of this version.

    Overrides
    object.ToString()

    TryParse(string, out SemVersion, bool)

    Converts the string representation of a semantic version to its SemVersion equivalent and returns a value that indicates whether the conversion succeeded.

    Declaration
    public static bool TryParse(string version, out SemVersion semver, bool strict = false)
    Parameters
    Type Name Description
    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 null if the version string was not valid.

    bool strict

    If set to true minor and patch version are required, otherwise they are optional.

    Returns
    Type Description
    bool

    false when a invalid version string is passed, otherwise true.

    Operators

    operator ==(SemVersion, SemVersion)

    Compares two semantic versions for equality.

    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
    bool

    If left is equal to right true, otherwise false.

    operator >(SemVersion, SemVersion)

    Compares two semantic versions.

    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
    bool

    If left is greater than right true, otherwise false.

    operator >=(SemVersion, SemVersion)

    Compares two semantic versions.

    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
    bool

    If left is greater than or equal to right true, otherwise false.

    implicit operator SemVersion(string)

    Implicit conversion from string to SemVersion.

    Declaration
    public static implicit operator SemVersion(string version)
    Parameters
    Type Name Description
    string version

    The semantic version.

    Returns
    Type Description
    SemVersion

    The SemVersion object.

    Exceptions
    Type Condition
    ArgumentNullException

    The version is null.

    ArgumentException

    The version number has an invalid format.

    OverflowException

    The Major, Minor, or Patch versions are larger than

    int.MaxValue
    .

    operator !=(SemVersion, SemVersion)

    Compares two semantic versions for inequality.

    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
    bool

    If left is not equal to right true, otherwise false.

    operator <(SemVersion, SemVersion)

    Compares two semantic versions.

    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
    bool

    If left is less than right true, otherwise false.

    operator <=(SemVersion, SemVersion)

    Compares two semantic versions.

    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
    bool

    If left is less than or equal to right true, otherwise false.

    Implements

    IComparable<T>
    IComparable
    ISerializable