summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/Globalization/SortVersion.cs
blob: 94c04d7063923cc1969500d15d44a1719728a560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Globalization
{
    [Serializable]
    public sealed class SortVersion : IEquatable<SortVersion>
    {
        private int m_NlsVersion; // Do not rename (binary serialization)
        private Guid m_SortId; // Do not rename (binary serialization)

        public int FullVersion
        {
            get
            {
                return m_NlsVersion;
            }
        }

        public Guid SortId
        {
            get
            {
                return m_SortId;
            }
        }

        public SortVersion(int fullVersion, Guid sortId)
        {
            m_SortId = sortId;
            m_NlsVersion = fullVersion;
        }

        internal SortVersion(int nlsVersion, int effectiveId, Guid customVersion)
        {
            m_NlsVersion = nlsVersion;

            if (customVersion == Guid.Empty)
            {
                byte b1 = (byte)(effectiveId >> 24);
                byte b2 = (byte)((effectiveId & 0x00FF0000) >> 16);
                byte b3 = (byte)((effectiveId & 0x0000FF00) >> 8);
                byte b4 = (byte)(effectiveId & 0xFF);
                customVersion = new Guid(0, 0, 0, 0, 0, 0, 0, b1, b2, b3, b4);
            }

            m_SortId = customVersion;
        }

        public override bool Equals(object obj)
        {
            SortVersion n = obj as SortVersion;
            if (n != null)
            {
                return this.Equals(n);
            }

            return false;
        }

        public bool Equals(SortVersion other)
        {
            if (other == null)
            {
                return false;
            }

            return m_NlsVersion == other.m_NlsVersion && m_SortId == other.m_SortId;
        }

        public override int GetHashCode()
        {
            return m_NlsVersion * 7 | m_SortId.GetHashCode();
        }

        public static bool operator ==(SortVersion left, SortVersion right)
        {
            if (((object)left) != null)
            {
                return left.Equals(right);
            }

            if (((object)right) != null)
            {
                return right.Equals(left);
            }

            // Both null.
            return true;
        }

        public static bool operator !=(SortVersion left, SortVersion right)
        {
            return !(left == right);
        }
    }
}