2
2
3
3
namespace Rubberduck . Common
4
4
{
5
- public struct WindowsVersion : IComparable < WindowsVersion >
5
+ public struct WindowsVersion : IComparable < WindowsVersion > , IEquatable < WindowsVersion >
6
6
{
7
- public static WindowsVersion Windows10 = new WindowsVersion ( 10 , 0 , 10240 ) ;
8
- public static WindowsVersion Windows81 = new WindowsVersion ( 6 , 3 , 9200 ) ;
9
- public static WindowsVersion Windows8 = new WindowsVersion ( 6 , 2 , 9200 ) ;
10
- public static WindowsVersion Windows7_SP1 = new WindowsVersion ( 6 , 1 , 7601 ) ;
11
- public static WindowsVersion WindowsVista_SP2 = new WindowsVersion ( 6 , 0 , 6002 ) ;
7
+ public static readonly WindowsVersion Windows10 = new WindowsVersion ( 10 , 0 , 10240 ) ;
8
+ public static readonly WindowsVersion Windows81 = new WindowsVersion ( 6 , 3 , 9200 ) ;
9
+ public static readonly WindowsVersion Windows8 = new WindowsVersion ( 6 , 2 , 9200 ) ;
10
+ public static readonly WindowsVersion Windows7_SP1 = new WindowsVersion ( 6 , 1 , 7601 ) ;
11
+ public static readonly WindowsVersion WindowsVista_SP2 = new WindowsVersion ( 6 , 0 , 6002 ) ;
12
12
13
13
public WindowsVersion ( int major , int minor , int build )
14
14
{
@@ -21,6 +21,7 @@ public WindowsVersion(int major, int minor, int build)
21
21
public int Minor { get ; }
22
22
public int Build { get ; }
23
23
24
+
24
25
public int CompareTo ( WindowsVersion other )
25
26
{
26
27
var majorComparison = Major . CompareTo ( other . Major ) ;
@@ -36,6 +37,27 @@ public int CompareTo(WindowsVersion other)
36
37
: Build . CompareTo ( other . Build ) ;
37
38
}
38
39
40
+ public bool Equals ( WindowsVersion other )
41
+ {
42
+ return Major == other . Major && Minor == other . Minor && Build == other . Build ;
43
+ }
44
+
45
+ public override bool Equals ( object other )
46
+ {
47
+ return other is WindowsVersion otherVersion && Equals ( otherVersion ) ;
48
+ }
49
+
50
+ public override int GetHashCode ( )
51
+ {
52
+ unchecked
53
+ {
54
+ var hashCode = Major ;
55
+ hashCode = ( hashCode * 397 ) ^ Minor ;
56
+ hashCode = ( hashCode * 397 ) ^ Build ;
57
+ return hashCode ;
58
+ }
59
+ }
60
+
39
61
public static bool operator == ( WindowsVersion os1 , WindowsVersion os2 )
40
62
{
41
63
return os1 . CompareTo ( os2 ) == 0 ;
0 commit comments