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