|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Linq; |
4 |
| - |
5 |
| -namespace Microsoft.OpenApi |
| 1 | +namespace Microsoft.OpenApi |
6 | 2 | {
|
7 | 3 | /// <summary>
|
8 | 4 | /// Dictionary extension methods
|
9 | 5 | /// </summary>
|
10 | 6 | internal static class CollectionExtensions
|
11 | 7 | {
|
12 |
| - /// <summary> |
13 |
| - /// Returns a new dictionary with entries sorted by key using a custom comparer. |
14 |
| - /// </summary> |
15 |
| - internal static IDictionary<TKey, TValue> Sort<TKey, TValue>( |
16 |
| - this IDictionary<TKey, TValue> source, |
17 |
| - IComparer<TKey> comparer) |
18 |
| - where TKey : notnull |
19 |
| - { |
20 |
| -#if NET7_0_OR_GREATER |
21 |
| - ArgumentNullException.ThrowIfNull(nameof(source)); |
22 |
| - ArgumentNullException.ThrowIfNull(nameof(comparer)); |
23 |
| -#else |
24 |
| - if (source == null) |
25 |
| - throw new ArgumentNullException(nameof(source)); |
26 |
| - if (comparer == null) |
27 |
| - throw new ArgumentNullException(nameof(comparer)); |
28 |
| -#endif |
29 |
| - return source.OrderBy(kvp => kvp.Key, comparer) |
30 |
| - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); |
31 |
| - } |
32 |
| - |
33 |
| - /// <summary> |
34 |
| - /// Sorts any IEnumerable<T> using the specified comparer and returns a List</T>. |
35 |
| - /// </summary> |
36 |
| - internal static List<T> Sort<T>(this IEnumerable<T> source, IComparer<T> comparer) |
37 |
| - { |
38 |
| -#if NET7_0_OR_GREATER |
39 |
| - ArgumentNullException.ThrowIfNull(source); |
40 |
| - ArgumentNullException.ThrowIfNull(comparer); |
41 |
| -#else |
42 |
| - if (source == null) |
43 |
| - throw new ArgumentNullException(nameof(source)); |
44 |
| - if (comparer == null) |
45 |
| - throw new ArgumentNullException(nameof(comparer)); |
46 |
| -#endif |
47 |
| - return source.OrderBy(item => item, comparer).ToList(); |
48 |
| - } |
49 | 8 | }
|
50 | 9 | }
|
0 commit comments