Compare versions numerically¶
This operation defines equality and ordering for Version instances. Rather than comparing the raw segment strings, it converts each of Major, Minor, Build, and Revision to an integer and compares those integers in Major → Minor → Build → Revision precedence. The same normalization and precedence rules back all four comparison operators and the IComparable implementation.
| Field | Value |
|---|---|
| Operation ID | OP-VER-003 |
| Trigger | Caller invokes CompareTo or operators =, <>, <, > |
| Inputs | Two Version instances, or obj As Object for CompareTo |
| Outputs | Boolean operator result or integer CompareTo result |
| Primary components | Version.CompareTo, Version.=, Version.<>, Version.<, Version.>, Extensions.ToInt |
| Entry point | SAIF.Framework.Version\Version.vb |
Steps¶
- If the caller used
CompareTo(obj), castobjtoSAIF.Framework.Version.Versionbefore any operator logic runs. - On failure: if
objisNothingor not aVersion, the cast throws and the exception bubbles unchanged to the caller. - Normalize every segment that will be compared by passing its string value through
ToInt(BR-001, BR-006). ToIntextracts only the leading run of digits, viaRegex.Match(value, "\d*").- On failure: if the extracted text still fails integer conversion, an empty
Catchblock swallows the error and the normalized value becomes0(BR-001). - For the
=operator, compare the normalizedMajor,Minor,Build, andRevisionpairs and returnTrueonly when all four match (BR-006). - For the
<>operator, run the same four-part equality test and return its logical negation. - For the
<and>operators, walk the normalized segments inMajor→Minor→Build→Revisionorder and stop as soon as one segment determines the relation (BR-006). - If an earlier segment already establishes the relation: return immediately without inspecting later segments.
- If every compared segment is equal: return
False— neither operator considers two equal versions to be less-than or greater-than each other. - Before the minor-segment comparison, both the
<and>operators evaluate a guard condition intended to confirm the majors are equal. As written, the condition comparesv2.Major.ToIntagainst itself (v2.Major.ToInt = v2.Major.ToInt) rather than againstv1.Major.ToInt(BR-007). - This guard is always
True, so it never actually re-verifies major equality at this point. - Execution still proceeds correctly in practice: the preceding major-based less-than/greater-than checks already gate entry into this branch, so the tautology does not currently change any returned result — but it should be corrected to compare
v1againstv2. - When invoked via
CompareTo, translate the operator outcomes into the standard contract: return0ifv2 = Me,1ifv2 < Me, and-1ifv2 > Me(BR-006).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Caller requests comparison]) --> Cast{Invoked via CompareTo?}
Cast -->|Yes| CastObj[Cast obj to Version]
Cast -->|No| Normalize[Normalize segment values via ToInt]
CastObj --> Normalize
Normalize --> Eq{Equality operator, or all segments equal?}
Eq -->|Yes| EndEq([Return true, or CompareTo 0])
Eq -->|No| Order[Compare Major then Minor then Build then Revision]
Order --> Result{Relation established by an earlier segment?}
Result -->|Yes| EndOrder([Return ordering result, or mapped CompareTo value])
Result -->|No| EndFalse([Return false — no relation established])
Failure and edge-case behavior¶
CompareTorelies on a direct cast of itsObjectparameter and performs no type check beyond that cast; an incompatible orNothingargument raises an unhandled exception.- Segment normalization discards any non-numeric suffix and coerces conversion failures to
0, so malformed segments never cause a comparison to fail — they simply compare as0(BR-001). - The
<and>operators contain the tautological major-equality guard described in BR-007; it is a likely copy-paste defect that does not currently affect comparison outcomes.
Related documentation¶
Sources¶
SAIF.Framework.Version\Version.vb