Mercurial > repos > IBBoard
changeset 104:80df73deb8fc
Re #48: Collection equality
* Swap fixed generic types (from auto-generation) for invocation-selected generic types
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 26 Apr 2011 14:57:34 +0000 |
parents | 8022850f7fd7 |
children | 13302d6dab55 |
files | Collections/Collections.cs |
diffstat | 1 files changed, 15 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Collections/Collections.cs Tue Apr 26 14:32:18 2011 +0000 +++ b/Collections/Collections.cs Tue Apr 26 14:57:34 2011 +0000 @@ -12,11 +12,15 @@ { } - public static bool AreEqual(IList<int> list1, IList<int> list2) + public static bool AreEqual<T, U> (IList<T> list1, IList<U> list2) { bool equal = true; - if (!EqualityChecker.AreEqual(list1, list2)) + if (typeof(T) != typeof(U)) + { + equal = false; + } + else if (!EqualityChecker.AreEqual(list1, list2)) { if (list1.Count != list2.Count) { @@ -40,11 +44,15 @@ return equal; } - public static bool AreEqual(IDictionary<string, int> dict1, IDictionary<string, int> dict2) + public static bool AreEqual<T,U,V,W>(IDictionary<T, U> dict1, IDictionary<V, W> dict2) where V : class { bool equal = true; - if (!EqualityChecker.AreEqual(dict1, dict2)) + if (typeof(T) != typeof(V) || typeof(U) != typeof(W)) + { + equal = false; + } + else if (!EqualityChecker.AreEqual(dict1, dict2)) { if (dict1.Count != dict2.Count) { @@ -52,9 +60,10 @@ } else { - foreach (KeyValuePair<string, int> pair in dict1) + foreach (KeyValuePair<T, U> pair in dict1) { - if (!dict2.ContainsKey(pair.Key) || !EqualityChecker.AreEqual(pair.Value, dict2[pair.Key])) + V key = pair.Key as V; + if (!dict2.ContainsKey(key) || !EqualityChecker.AreEqual(pair.Value, dict2[key])) { equal = false; break;