/// <summary> /// Checks if version provided is higher than the crrent instance. In /// contrast to <c>CompareTo</c> methods, for a version component /// containing asterisk, the pattern provided is assumed to be higher. /// </summary> /// <param name="pattern"> /// String presentation of a version. /// </param> /// <returns> /// <c>true</c> if pattern provided is higher version. /// </returns> public bool IsStringPatternHigher(string pattern) { VersionNumber other = new VersionNumber(pattern); int[] vc1 = ComparableComponents; int[] vc2 = other.ComparableComponents; for (int i = 0; i < 4; i++) { if (vc1[i] != vc2[i]) { return(vc2[i] > vc1[i]); } // if component is asterisk, then string pattern will be higher if (vc1[i] == MaxVersion && vc2[i] == MaxVersion) { return(true); } } return(false); }
/// <summary> /// Returns higher of two <c>ProjectVersion</c> objects provided. /// </summary> /// <param name="v1"> /// First <c>ProjectVersion</c> to compare. /// </param> /// <param name="v2"> /// Second <c>ProjectVersion</c> to compare. /// </param> /// <returns> /// Reference two higher <c>ProjectVersion</c> objects. /// </returns> public static VersionNumber Max(VersionNumber v1, VersionNumber v2) { int[] vc1 = v1.ComparableComponents; int[] vc2 = v2.ComparableComponents; for (int i = 0; i < 4; i++) { if (vc1[i] != vc2[i]) { // if both aren't wildcards, return the larger if (vc1[i] != MaxVersion && vc2[i] != MaxVersion) { return(vc1[i] > vc2[i] ? v1 : v2); } else { return(vc1[i] != MaxVersion ? v1 : v2); } } } return(v1); }
/// <summary> /// Compares this version with a string presentation of another /// instance. /// </summary> /// <param name="other"> /// String presentation of the <c>ProjectVersion</c> to compare to. /// </param> /// <returns> /// 0 if versions are equal, negative number if this instance /// is a lower version or positive number if this instance is a /// higher version than the version provided. /// </returns> public int CompareTo(string other) { VersionNumber otherVersion = new VersionNumber(other); return(CompareTo(otherVersion)); }