Merge pull request #3522 from henricm/fix-csharp-compiler-path-windows
[mono.git] / mcs / class / referencesource / mscorlib / system / globalization / sortversion.cs
1 using System;
2 using System.Diagnostics.Contracts;
3
4 namespace System.Globalization {
5
6     [Serializable]
7     public sealed class SortVersion : IEquatable<SortVersion> {
8
9         private int m_NlsVersion;
10         private Guid m_SortId;
11
12         public int FullVersion {
13             get {
14                 return m_NlsVersion;
15             }
16         }
17
18         public Guid SortId {
19             get {
20                 return m_SortId;
21             }
22         }
23
24         public SortVersion(int fullVersion, Guid sortId) {           
25             m_SortId = sortId;
26             m_NlsVersion = fullVersion;
27         }
28
29         internal SortVersion(int nlsVersion, int effectiveId, Guid customVersion) {
30             m_NlsVersion = nlsVersion;
31
32             if(customVersion == Guid.Empty) {
33 #if !MONO                
34                 byte[] b = BitConverter.GetBytes(effectiveId);
35 #endif
36                 byte b1 = (byte) ((uint) effectiveId >> 24);
37                 byte b2 = (byte) ((effectiveId  & 0x00FF0000) >> 16);
38                 byte b3 = (byte) ((effectiveId  & 0x0000FF00) >> 8);
39                 byte b4 = (byte) (effectiveId  & 0xFF);
40                 customVersion = new Guid(0,0,0,0,0,0,0,b1,b2,b3,b4);
41             }
42
43             m_SortId = customVersion;
44         }
45
46         public override bool Equals(object obj) {
47             SortVersion n = obj as SortVersion;
48             if(n != null) {
49                 return this.Equals(n);
50             }
51
52             return false;
53         }
54
55         public bool Equals(SortVersion other) {
56             if(other == null) {
57                 return false;
58             }
59
60             return m_NlsVersion == other.m_NlsVersion && m_SortId == other.m_SortId;
61         }
62
63         public override int GetHashCode() { 
64             return m_NlsVersion * 7 | m_SortId.GetHashCode(); 
65         }
66
67         public static bool operator ==(SortVersion left, SortVersion right) {
68             if (((object) left) != null) {
69                 return left.Equals(right);
70             }
71
72             if (((object) right) != null) {
73                 return right.Equals(left);
74             }
75
76             // Both null.
77             return true;
78         }
79
80         public static bool operator !=(SortVersion left, SortVersion right) {
81             return !(left == right);
82         }
83     }
84 }