wasSharp – Blame information for rev 10

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 // Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 //
16 ///////////////////////////////////////////////////////////////////////////
17 /// <summary>
18 /// Returns true of an enumerable contains more than one element.
19 /// </summary>
20 /// <typeparam name="T">the type of the enumeration</typeparam>
21 /// <param name="e">the enumeration</param>
22 /// <returns>true if enumeration contains more than one element</returns>
23 /// <remarks>O(2) worst case</remarks>
24 public static bool Some<T>(this IEnumerable<T> e)
25 {
26 var i = 0;
27 using (var iter = e.GetEnumerator())
28 {
29 while (iter.MoveNext())
30 {
31 if (++i > 1)
32 return true;
33 }
34 return false;
35 }
36 }
37  
38 /// <summary>
39 /// Compares two dictionaries for equality.
40 /// </summary>
41 /// <typeparam name="TKey">key type</typeparam>
42 /// <typeparam name="TValue">value type</typeparam>
43 /// <param name="dictionary">dictionary to compare</param>
44 /// <param name="otherDictionary">dictionary to compare to</param>
45 /// <returns>true if the dictionaries contain the same elements</returns>
46 public static bool ContentEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary,
47 IDictionary<TKey, TValue> otherDictionary)
48 {
49 return
50 (dictionary ?? new Dictionary<TKey, TValue>()).Count.Equals(
51 (otherDictionary ?? new Dictionary<TKey, TValue>()).Count) &&
52 (otherDictionary ?? new Dictionary<TKey, TValue>())
53 .OrderBy(kvp => kvp.Key)
54 .SequenceEqual((dictionary ?? new Dictionary<TKey, TValue>())
55 .OrderBy(kvp => kvp.Key));
56 }
57 }
58 }