wasSharp – Blame information for rev 12
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
10 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System.Collections.Generic; |
||
8 | using System.Linq; |
||
9 | |||
10 | namespace wasSharp.Collections.Utilities |
||
11 | { |
||
12 | public static class Extensions |
||
13 | { |
||
14 | /// <summary> |
||
15 | /// Compares two dictionaries for equality. |
||
16 | /// </summary> |
||
17 | /// <typeparam name="TKey">key type</typeparam> |
||
18 | /// <typeparam name="TValue">value type</typeparam> |
||
19 | /// <param name="dictionary">dictionary to compare</param> |
||
20 | /// <param name="otherDictionary">dictionary to compare to</param> |
||
21 | /// <returns>true if the dictionaries contain the same elements</returns> |
||
22 | public static bool ContentEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, |
||
23 | IDictionary<TKey, TValue> otherDictionary) |
||
24 | { |
||
25 | return |
||
26 | (dictionary ?? new Dictionary<TKey, TValue>()).Count.Equals( |
||
27 | (otherDictionary ?? new Dictionary<TKey, TValue>()).Count) && |
||
28 | (otherDictionary ?? new Dictionary<TKey, TValue>()) |
||
29 | .OrderBy(kvp => kvp.Key) |
||
30 | .SequenceEqual((dictionary ?? new Dictionary<TKey, TValue>()) |
||
31 | .OrderBy(kvp => kvp.Key)); |
||
32 | } |
||
33 | } |
||
34 | } |