| | 1 | | using System.Collections.ObjectModel; |
| | 2 | |
|
| | 3 | | namespace Fluorite.Extensions; |
| | 4 | |
|
| | 5 | | public static class EnumerableExtensions |
| | 6 | | { |
| | 7 | | public static IEnumerable<T> Concat<T>( |
| | 8 | | this IEnumerable<T> source, |
| | 9 | | params IEnumerable<T>[] sequences) |
| | 10 | | { |
| 2 | 11 | | Guard.Against.Null(source); |
| 2 | 12 | | Guard.Against.Null(sequences); |
| | 13 | |
|
| 10 | 14 | | return Enumerable.Concat(source, sequences.SelectMany(x => x)); |
| | 15 | | } |
| | 16 | |
|
| | 17 | | public static Dictionary<TKey, TValue> Merge<TKey, TValue>( |
| | 18 | | this IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs) |
| | 19 | | { |
| 52 | 20 | | Guard.Against.Null(keyValuePairs); |
| | 21 | |
|
| 52 | 22 | | var result = new Dictionary<TKey, TValue>(); |
| | 23 | |
|
| 124 | 24 | | foreach (var pair in keyValuePairs) |
| | 25 | | { |
| 10 | 26 | | result.Add(pair.Key, pair.Value); |
| | 27 | | } |
| | 28 | |
|
| 52 | 29 | | return result; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>( |
| | 33 | | this IEnumerable<KeyValuePair<TKey, TValue>> source) |
| | 34 | | { |
| 12 | 35 | | Guard.Against.Null(source); |
| | 36 | |
|
| 454 | 37 | | return source.ToDictionary(pair => pair.Key, pair => pair.Value); |
| | 38 | | } |
| | 39 | |
|
| | 40 | | public static ReadOnlyDictionary<TKey, TValue> ToReadOnlyDictionary<TKey, TValue>( |
| | 41 | | this IEnumerable<KeyValuePair<TKey, TValue>> source) |
| | 42 | | { |
| 12 | 43 | | Guard.Against.Null(source); |
| | 44 | |
|
| 12 | 45 | | return new ReadOnlyDictionary<TKey, TValue>(source.ToDictionary()); |
| | 46 | | } |
| | 47 | | } |