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 diff
     1.1 --- a/Collections/Collections.cs	Tue Apr 26 14:32:18 2011 +0000
     1.2 +++ b/Collections/Collections.cs	Tue Apr 26 14:57:34 2011 +0000
     1.3 @@ -12,11 +12,15 @@
     1.4  		{
     1.5  		}
     1.6  
     1.7 -		public static bool AreEqual(IList<int> list1, IList<int> list2)
     1.8 +		public static bool AreEqual<T, U> (IList<T> list1, IList<U> list2)
     1.9  		{
    1.10  			bool equal = true;
    1.11  
    1.12 -			if (!EqualityChecker.AreEqual(list1, list2))
    1.13 +			if (typeof(T) != typeof(U))
    1.14 +			{
    1.15 +				equal = false;
    1.16 +			}
    1.17 +			else if (!EqualityChecker.AreEqual(list1, list2))
    1.18  			{
    1.19  				if (list1.Count != list2.Count)
    1.20  				{
    1.21 @@ -40,11 +44,15 @@
    1.22  			return equal;
    1.23  		}
    1.24  
    1.25 -		public static bool AreEqual(IDictionary<string, int> dict1, IDictionary<string, int> dict2)
    1.26 +		public static bool AreEqual<T,U,V,W>(IDictionary<T, U> dict1, IDictionary<V, W> dict2) where V : class
    1.27  		{
    1.28  			bool equal = true;
    1.29  
    1.30 -			if (!EqualityChecker.AreEqual(dict1, dict2))
    1.31 +			if (typeof(T) != typeof(V) || typeof(U) != typeof(W))
    1.32 +			{
    1.33 +				equal = false;
    1.34 +			}
    1.35 +			else if (!EqualityChecker.AreEqual(dict1, dict2))
    1.36  			{
    1.37  				if (dict1.Count != dict2.Count)
    1.38  				{
    1.39 @@ -52,9 +60,10 @@
    1.40  				}
    1.41  				else
    1.42  				{
    1.43 -					foreach (KeyValuePair<string, int> pair in dict1)
    1.44 +					foreach (KeyValuePair<T, U> pair in dict1)
    1.45  					{
    1.46 -						if (!dict2.ContainsKey(pair.Key) || !EqualityChecker.AreEqual(pair.Value, dict2[pair.Key]))
    1.47 +						V key = pair.Key as V;
    1.48 +						if (!dict2.ContainsKey(key) || !EqualityChecker.AreEqual(pair.Value, dict2[key]))
    1.49  						{
    1.50  							equal = false;
    1.51  							break;