wasSharp – Blame information for rev 11

Subversion Repositories:
Rev:
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  
15 /// <summary>
16 /// Compares two dictionaries for equality.
17 /// </summary>
18 /// <typeparam name="TKey">key type</typeparam>
19 /// <typeparam name="TValue">value type</typeparam>
20 /// <param name="dictionary">dictionary to compare</param>
21 /// <param name="otherDictionary">dictionary to compare to</param>
22 /// <returns>true if the dictionaries contain the same elements</returns>
23 public static bool ContentEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary,
24 IDictionary<TKey, TValue> otherDictionary)
25 {
26 return
27 (dictionary ?? new Dictionary<TKey, TValue>()).Count.Equals(
28 (otherDictionary ?? new Dictionary<TKey, TValue>()).Count) &&
29 (otherDictionary ?? new Dictionary<TKey, TValue>())
30 .OrderBy(kvp => kvp.Key)
31 .SequenceEqual((dictionary ?? new Dictionary<TKey, TValue>())
32 .OrderBy(kvp => kvp.Key));
33 }
34 }
35 }