| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics.CodeAnalysis; |
| | | 5 | | using System.Runtime.CompilerServices; |
| | | 6 | | |
| | | 7 | | namespace System.Globalization |
| | | 8 | | { |
| | | 9 | | [Serializable] |
| | | 10 | | [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] |
| | | 11 | | public sealed class SortVersion : IEquatable<SortVersion?> |
| | | 12 | | { |
| | | 13 | | private readonly int m_NlsVersion; // Do not rename (binary serialization) |
| | | 14 | | private readonly Guid m_SortId; // Do not rename (binary serialization) |
| | | 15 | | |
| | 0 | 16 | | public int FullVersion => m_NlsVersion; |
| | | 17 | | |
| | 0 | 18 | | public Guid SortId => m_SortId; |
| | | 19 | | |
| | 0 | 20 | | public SortVersion(int fullVersion, Guid sortId) |
| | | 21 | | { |
| | 0 | 22 | | m_SortId = sortId; |
| | 0 | 23 | | m_NlsVersion = fullVersion; |
| | 0 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | internal SortVersion(int nlsVersion, int effectiveId, Guid customVersion) |
| | | 27 | | { |
| | 0 | 28 | | m_NlsVersion = nlsVersion; |
| | | 29 | | |
| | 0 | 30 | | if (customVersion == Guid.Empty) |
| | | 31 | | { |
| | 0 | 32 | | byte b1 = (byte)(effectiveId >> 24); |
| | 0 | 33 | | byte b2 = (byte)((effectiveId & 0x00FF0000) >> 16); |
| | 0 | 34 | | byte b3 = (byte)((effectiveId & 0x0000FF00) >> 8); |
| | 0 | 35 | | byte b4 = (byte)(effectiveId & 0xFF); |
| | 0 | 36 | | customVersion = new Guid(0, 0, 0, 0, 0, 0, 0, b1, b2, b3, b4); |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | m_SortId = customVersion; |
| | 0 | 40 | | } |
| | | 41 | | |
| | | 42 | | public override bool Equals([NotNullWhen(true)] object? obj) |
| | | 43 | | { |
| | 0 | 44 | | return obj is SortVersion otherVersion && Equals(otherVersion); |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public bool Equals([NotNullWhen(true)] SortVersion? other) |
| | | 48 | | { |
| | 0 | 49 | | if (other == null) |
| | | 50 | | { |
| | 0 | 51 | | return false; |
| | | 52 | | } |
| | | 53 | | |
| | 0 | 54 | | return m_NlsVersion == other.m_NlsVersion && m_SortId == other.m_SortId; |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | public override int GetHashCode() |
| | | 58 | | { |
| | 0 | 59 | | return m_NlsVersion * 7 | m_SortId.GetHashCode(); |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 63 | | public static bool operator ==(SortVersion? left, SortVersion? right) |
| | | 64 | | { |
| | | 65 | | // Test "right" first to allow branch elimination when inlined for null checks (== null) |
| | | 66 | | // so it can become a simple test |
| | 0 | 67 | | if (right is null) |
| | | 68 | | { |
| | 0 | 69 | | return left is null; |
| | | 70 | | } |
| | | 71 | | |
| | 0 | 72 | | return right.Equals(left); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | public static bool operator !=(SortVersion? left, SortVersion? right) => |
| | 0 | 76 | | !(left == right); |
| | | 77 | | } |
| | | 78 | | } |
| | | 79 | | |