|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 |
| -namespace Microsoft.EntityFrameworkCore.Cosmos.ChangeTracking.Internal; |
5 |
| - |
6 |
| -/// <summary> |
7 |
| -/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
8 |
| -/// the same compatibility standards as public APIs. It may be changed or removed without notice in |
9 |
| -/// any release. You should only use it directly in your code with extreme caution and knowing that |
10 |
| -/// doing so can result in application failures when updating to a new Entity Framework Core release. |
11 |
| -/// </summary> |
12 |
| -public sealed class NullableListComparer<TElement, TCollection> : ValueComparer<TCollection> |
13 |
| - where TCollection : class, IEnumerable<TElement?> |
14 |
| - where TElement : struct |
15 |
| -{ |
16 |
| - /// <summary> |
17 |
| - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
18 |
| - /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
19 |
| - /// any release. You should only use it directly in your code with extreme caution and knowing that |
20 |
| - /// doing so can result in application failures when updating to a new Entity Framework Core release. |
21 |
| - /// </summary> |
22 |
| - public NullableListComparer(ValueComparer elementComparer, bool readOnly) |
23 |
| - : base( |
24 |
| - (a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer), |
25 |
| - o => GetHashCode(o, (ValueComparer<TElement>)elementComparer), |
26 |
| - source => Snapshot(source, (ValueComparer<TElement>)elementComparer, readOnly)) |
27 |
| - { |
28 |
| - } |
29 |
| - |
30 |
| - /// <summary> |
31 |
| - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
32 |
| - /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
33 |
| - /// any release. You should only use it directly in your code with extreme caution and knowing that |
34 |
| - /// doing so can result in application failures when updating to a new Entity Framework Core release. |
35 |
| - /// </summary> |
36 |
| - public override Type Type |
37 |
| - => typeof(TCollection); |
38 |
| - |
39 |
| - private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TElement> elementComparer) |
40 |
| - { |
41 |
| - if (a is not IReadOnlyList<TElement?> aList) |
42 |
| - { |
43 |
| - return b is not IReadOnlyList<TElement?>; |
44 |
| - } |
45 |
| - |
46 |
| - if (b is not IReadOnlyList<TElement?> bList || aList.Count != bList.Count) |
47 |
| - { |
48 |
| - return false; |
49 |
| - } |
50 |
| - |
51 |
| - if (ReferenceEquals(aList, bList)) |
52 |
| - { |
53 |
| - return true; |
54 |
| - } |
55 |
| - |
56 |
| - for (var i = 0; i < aList.Count; i++) |
57 |
| - { |
58 |
| - var (aElement, bElement) = (aList[i], bList[i]); |
59 |
| - if (aElement is null) |
60 |
| - { |
61 |
| - if (bElement is null) |
62 |
| - { |
63 |
| - continue; |
64 |
| - } |
65 |
| - |
66 |
| - return false; |
67 |
| - } |
68 |
| - |
69 |
| - if (bElement is null || !elementComparer.Equals(aElement, bElement)) |
70 |
| - { |
71 |
| - return false; |
72 |
| - } |
73 |
| - } |
74 |
| - |
75 |
| - return true; |
76 |
| - } |
77 |
| - |
78 |
| - private static int GetHashCode(TCollection source, ValueComparer<TElement> elementComparer) |
79 |
| - { |
80 |
| - var nullableEqualityComparer = new NullableEqualityComparer<TElement>(elementComparer); |
81 |
| - var hash = new HashCode(); |
82 |
| - foreach (var el in source) |
83 |
| - { |
84 |
| - hash.Add(el, nullableEqualityComparer); |
85 |
| - } |
86 |
| - |
87 |
| - return hash.ToHashCode(); |
88 |
| - } |
89 |
| - |
90 |
| - private static TCollection Snapshot(TCollection source, ValueComparer<TElement> elementComparer, bool readOnly) |
91 |
| - { |
92 |
| - if (readOnly) |
93 |
| - { |
94 |
| - return source; |
95 |
| - } |
96 |
| - |
97 |
| - var snapshot = new List<TElement?>(((IReadOnlyList<TElement?>)source).Count); |
98 |
| - foreach (var e in source) |
99 |
| - { |
100 |
| - snapshot.Add(e is null ? null : elementComparer.Snapshot(e.Value)); |
101 |
| - } |
102 |
| - |
103 |
| - return (TCollection)(object)snapshot; |
104 |
| - } |
105 |
| -} |
| 4 | +// namespace Microsoft.EntityFrameworkCore.Cosmos.ChangeTracking.Internal; |
| 5 | +// |
| 6 | +// /// <summary> |
| 7 | +// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 8 | +// /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 9 | +// /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 10 | +// /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 11 | +// /// </summary> |
| 12 | +// public sealed class NullableListComparer<TElement, TCollection> : ValueComparer<TCollection> |
| 13 | +// where TCollection : class, IEnumerable<TElement?> |
| 14 | +// where TElement : struct |
| 15 | +// { |
| 16 | +// /// <summary> |
| 17 | +// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 18 | +// /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 19 | +// /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 20 | +// /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 21 | +// /// </summary> |
| 22 | +// public NullableListComparer(ValueComparer elementComparer, bool readOnly) |
| 23 | +// : base( |
| 24 | +// (a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer), |
| 25 | +// o => GetHashCode(o, (ValueComparer<TElement>)elementComparer), |
| 26 | +// source => Snapshot(source, (ValueComparer<TElement>)elementComparer, readOnly)) |
| 27 | +// { |
| 28 | +// } |
| 29 | +// |
| 30 | +// /// <summary> |
| 31 | +// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to |
| 32 | +// /// the same compatibility standards as public APIs. It may be changed or removed without notice in |
| 33 | +// /// any release. You should only use it directly in your code with extreme caution and knowing that |
| 34 | +// /// doing so can result in application failures when updating to a new Entity Framework Core release. |
| 35 | +// /// </summary> |
| 36 | +// public override Type Type |
| 37 | +// => typeof(TCollection); |
| 38 | +// |
| 39 | +// private static bool Compare(TCollection? a, TCollection? b, ValueComparer<TElement> elementComparer) |
| 40 | +// { |
| 41 | +// if (a is not IReadOnlyList<TElement?> aList) |
| 42 | +// { |
| 43 | +// return b is not IReadOnlyList<TElement?>; |
| 44 | +// } |
| 45 | +// |
| 46 | +// if (b is not IReadOnlyList<TElement?> bList || aList.Count != bList.Count) |
| 47 | +// { |
| 48 | +// return false; |
| 49 | +// } |
| 50 | +// |
| 51 | +// if (ReferenceEquals(aList, bList)) |
| 52 | +// { |
| 53 | +// return true; |
| 54 | +// } |
| 55 | +// |
| 56 | +// for (var i = 0; i < aList.Count; i++) |
| 57 | +// { |
| 58 | +// var (aElement, bElement) = (aList[i], bList[i]); |
| 59 | +// if (aElement is null) |
| 60 | +// { |
| 61 | +// if (bElement is null) |
| 62 | +// { |
| 63 | +// continue; |
| 64 | +// } |
| 65 | +// |
| 66 | +// return false; |
| 67 | +// } |
| 68 | +// |
| 69 | +// if (bElement is null || !elementComparer.Equals(aElement, bElement)) |
| 70 | +// { |
| 71 | +// return false; |
| 72 | +// } |
| 73 | +// } |
| 74 | +// |
| 75 | +// return true; |
| 76 | +// } |
| 77 | +// |
| 78 | +// private static int GetHashCode(TCollection source, ValueComparer<TElement> elementComparer) |
| 79 | +// { |
| 80 | +// var nullableEqualityComparer = new NullableEqualityComparer<TElement>(elementComparer); |
| 81 | +// var hash = new HashCode(); |
| 82 | +// foreach (var el in source) |
| 83 | +// { |
| 84 | +// hash.Add(el, nullableEqualityComparer); |
| 85 | +// } |
| 86 | +// |
| 87 | +// return hash.ToHashCode(); |
| 88 | +// } |
| 89 | +// |
| 90 | +// private static TCollection Snapshot(TCollection source, ValueComparer<TElement> elementComparer, bool readOnly) |
| 91 | +// { |
| 92 | +// if (readOnly) |
| 93 | +// { |
| 94 | +// return source; |
| 95 | +// } |
| 96 | +// |
| 97 | +// var snapshot = new List<TElement?>(((IReadOnlyList<TElement?>)source).Count); |
| 98 | +// foreach (var e in source) |
| 99 | +// { |
| 100 | +// snapshot.Add(e is null ? null : elementComparer.Snapshot(e.Value)); |
| 101 | +// } |
| 102 | +// |
| 103 | +// return (TCollection)(object)snapshot; |
| 104 | +// } |
| 105 | +// } |
0 commit comments