| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Diagnostics; |
| | 6 | |
|
| | 7 | | namespace Azure.Data.Tables.Queryable |
| | 8 | | { |
| | 9 | |
|
| | 10 | | internal sealed class ReferenceEqualityComparer<T> : ReferenceEqualityComparer, IEqualityComparer<T> |
| | 11 | | { |
| | 12 | | private static ReferenceEqualityComparer<T> s_instance; |
| | 13 | |
|
| | 14 | | private ReferenceEqualityComparer() |
| 2 | 15 | | : base() |
| | 16 | | { |
| 2 | 17 | | } |
| | 18 | |
|
| | 19 | | internal static ReferenceEqualityComparer<T> Instance |
| | 20 | | { |
| | 21 | | get |
| | 22 | | { |
| 920 | 23 | | if (s_instance == null) |
| | 24 | | { |
| | 25 | | Debug.Assert(!typeof(T).IsValueType, "!typeof(T).IsValueType -- can't use reference equality in a me |
| 2 | 26 | | ReferenceEqualityComparer<T> newInstance = new ReferenceEqualityComparer<T>(); |
| 2 | 27 | | System.Threading.Interlocked.CompareExchange(ref s_instance, newInstance, null); |
| | 28 | | } |
| | 29 | |
|
| 920 | 30 | | return s_instance; |
| | 31 | | } |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public bool Equals(T x, T y) |
| | 35 | | { |
| 64 | 36 | | return object.ReferenceEquals(x, y); |
| | 37 | | } |
| | 38 | |
|
| | 39 | | public int GetHashCode(T obj) |
| | 40 | | { |
| 670 | 41 | | if (obj == null) |
| | 42 | | { |
| 0 | 43 | | return 0; |
| | 44 | | } |
| | 45 | |
|
| 670 | 46 | | return obj.GetHashCode(); |
| | 47 | | } |
| | 48 | |
|
| | 49 | | } |
| | 50 | | } |