[497] | 1 | ' Classes/System/Version.ab
|
---|
[142] | 2 |
|
---|
[257] | 3 | Namespace System
|
---|
| 4 |
|
---|
[142] | 5 | Class Version
|
---|
| 6 | ' Inherits ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
|
---|
| 7 | Public
|
---|
| 8 | ' Constractor
|
---|
| 9 | Sub Version()
|
---|
| 10 | major = 0
|
---|
| 11 | minor = 0
|
---|
| 12 | build = -1
|
---|
| 13 | revision = -1
|
---|
| 14 | End Sub
|
---|
| 15 |
|
---|
| 16 | 'Sub Version(s As String)
|
---|
| 17 | 'End Sub
|
---|
| 18 |
|
---|
| 19 | Sub Version(major As Long, minor As Long)
|
---|
| 20 | This.major = major
|
---|
| 21 | This.minor = minor
|
---|
[212] | 22 | This.build = -1
|
---|
| 23 | This.revision = -1
|
---|
[142] | 24 | End Sub
|
---|
| 25 |
|
---|
| 26 | Sub Version(major As Long, minor As Long, build As Long)
|
---|
| 27 | This.major = major
|
---|
| 28 | This.minor = minor
|
---|
| 29 | This.build = build
|
---|
[212] | 30 | This.revision = -1
|
---|
[142] | 31 | End Sub
|
---|
| 32 |
|
---|
[161] | 33 | Sub Version(major As Long, minor As Long, build As Long, revision As Long)
|
---|
[142] | 34 | This.major = major
|
---|
| 35 | This.minor = minor
|
---|
| 36 | This.build = build
|
---|
| 37 | This.revision = revision
|
---|
| 38 | End Sub
|
---|
| 39 |
|
---|
| 40 | Const Function Major() As Long
|
---|
| 41 | Return major
|
---|
| 42 | End Function
|
---|
| 43 |
|
---|
| 44 | Const Function Minor() As Long
|
---|
| 45 | Return minor
|
---|
| 46 | End Function
|
---|
| 47 |
|
---|
| 48 | Const Function Build() As Long
|
---|
| 49 | Return build
|
---|
| 50 | End Function
|
---|
| 51 |
|
---|
| 52 | Const Function Revision() As Long
|
---|
| 53 | Return revision
|
---|
| 54 | End Function
|
---|
| 55 |
|
---|
[233] | 56 | Const Function MajorRevision() As Integer
|
---|
[142] | 57 | Return HIWORD(revision) As Integer
|
---|
| 58 | End Function
|
---|
| 59 |
|
---|
[233] | 60 | Const Function MinorRevision() As Integer
|
---|
[142] | 61 | Return LOWORD(revision) As Integer
|
---|
| 62 | End Function
|
---|
| 63 |
|
---|
| 64 | Const Function CompareTo(v As Version) As Long
|
---|
| 65 | CompareTo = major - v.major
|
---|
| 66 | If CompareTo <> 0 Then Exit Function
|
---|
| 67 | CompareTo = minor - v.minor
|
---|
| 68 | If CompareTo <> 0 Then Exit Function
|
---|
| 69 | CompareTo = build - v.build
|
---|
| 70 | If CompareTo <> 0 Then Exit Function
|
---|
[233] | 71 | CompareTo = revision - v.revision
|
---|
[142] | 72 | End Function
|
---|
| 73 |
|
---|
| 74 | Const Function Equals(v As Version) As Boolean
|
---|
| 75 | Return CompareTo(v) = 0
|
---|
| 76 | End Function
|
---|
| 77 |
|
---|
| 78 | Override Function GetHashCode() As Long
|
---|
[233] | 79 | Return _System_BSwap(major As DWord) Xor minor Xor build Xor _System_BSwap(revision As DWord)
|
---|
[142] | 80 | End Function
|
---|
| 81 |
|
---|
| 82 | Function Operator ==(v As Version) As Boolean
|
---|
| 83 | Return CompareTo(v) = 0
|
---|
| 84 | End Function
|
---|
| 85 |
|
---|
| 86 | Function Operator <>(v As Version) As Boolean
|
---|
| 87 | Return CompareTo(v) <> 0
|
---|
| 88 | End Function
|
---|
| 89 |
|
---|
| 90 | Function Operator <(v As Version) As Boolean
|
---|
| 91 | Return CompareTo(v) < 0
|
---|
| 92 | End Function
|
---|
| 93 |
|
---|
| 94 | Function Operator >(v As Version) As Boolean
|
---|
| 95 | Return CompareTo(v) > 0
|
---|
| 96 | End Function
|
---|
| 97 |
|
---|
| 98 | Function Operator <=(v As Version) As Boolean
|
---|
| 99 | Return CompareTo(v) <= 0
|
---|
| 100 | End Function
|
---|
| 101 |
|
---|
| 102 | Function Operator >=(v As Version) As Boolean
|
---|
| 103 | Return CompareTo(v) >= 0
|
---|
| 104 | End Function
|
---|
| 105 |
|
---|
| 106 | Override Function ToString() As String
|
---|
| 107 | ToString = Str$(major) + "." + Str$(minor)
|
---|
| 108 | If build >= 0 Then
|
---|
| 109 | ToString = ToString + "." + Str$(build)
|
---|
[233] | 110 | If revision >= 0 Then
|
---|
| 111 | ToString = ToString + "." + Str$(revision)
|
---|
[142] | 112 | End If
|
---|
| 113 | End If
|
---|
| 114 | End Function
|
---|
| 115 |
|
---|
| 116 | Function ToString(fieldCount As Long) As String
|
---|
| 117 | If fieldCount < 0 Or fieldCount > 4 Then
|
---|
[497] | 118 | Throw New ArgumentOutOfRangeException("fieldCount")
|
---|
[142] | 119 | End If
|
---|
| 120 | ToString = ""
|
---|
| 121 | If fieldCount = 0 Then Exit Function
|
---|
| 122 | ToString = Str$(major)
|
---|
| 123 | If fieldCount = 1 Then Exit Function
|
---|
[212] | 124 | ToString = ToString + "." + Str$(minor)
|
---|
[142] | 125 | If fieldCount = 2 Then Exit Function
|
---|
| 126 |
|
---|
| 127 | If build < 0 Then
|
---|
[497] | 128 | Throw New ArgumentException
|
---|
[142] | 129 | End If
|
---|
[212] | 130 | ToString = ToString + "." + Str$(build)
|
---|
[142] | 131 | If fieldCount = 3 Then Exit Function
|
---|
| 132 |
|
---|
[233] | 133 | If revision < 0 Then
|
---|
[497] | 134 | Throw New ArgumentException
|
---|
[142] | 135 | End If
|
---|
[233] | 136 | ToString = ToString + "." + Str$(revision)
|
---|
[142] | 137 | End Function
|
---|
| 138 | Private
|
---|
| 139 | major As Long
|
---|
| 140 | minor As Long
|
---|
| 141 | build As Long
|
---|
[233] | 142 | revision As Long
|
---|
[142] | 143 | End Class
|
---|
[175] | 144 |
|
---|
[257] | 145 | End Namespace 'System
|
---|