Using running process to determine mono exe path on 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                 byte[] b = BitConverter.GetBytes(effectiveId);
34                 byte b1 = (byte) ((uint) effectiveId >> 24);
35                 byte b2 = (byte) ((effectiveId  & 0x00FF0000) >> 16);
36                 byte b3 = (byte) ((effectiveId  & 0x0000FF00) >> 8);
37                 byte b4 = (byte) (effectiveId  & 0xFF);
38                 customVersion = new Guid(0,0,0,0,0,0,0,b1,b2,b3,b4);
39             }
40
41             m_SortId = customVersion;
42         }
43
44         public override bool Equals(object obj) {
45             SortVersion n = obj as SortVersion;
46             if(n != null) {
47                 return this.Equals(n);
48             }
49
50             return false;
51         }
52
53         public bool Equals(SortVersion other) {
54             if(other == null) {
55                 return false;
56             }
57
58             return m_NlsVersion == other.m_NlsVersion && m_SortId == other.m_SortId;
59         }
60
61         public override int GetHashCode() { 
62             return m_NlsVersion * 7 | m_SortId.GetHashCode(); 
63         }
64
65         public static bool operator ==(SortVersion left, SortVersion right) {
66             if (((object) left) != null) {
67                 return left.Equals(right);
68             }
69
70             if (((object) right) != null) {
71                 return right.Equals(left);
72             }
73
74             // Both null.
75             return true;
76         }
77
78         public static bool operator !=(SortVersion left, SortVersion right) {
79             return !(left == right);
80         }
81     }
82 }