/// <summary>
/// This method determines whether the provided collections are equal.
/// </summary>
/// <param name="left"> The first collection. </param>
/// <param name="right"> The second collection. </param>
/// <returns> <c>true</c> when both collections are equal; otherwise, <c>false</c> . </returns>
/// <remarks>
/// <para>This method begins by comparing the reference to the collections
/// themselves and returns
/// <c>true</c>
/// when they are both null.
/// Secondly it returns
/// <c>false</c>
/// whenever one of both references
/// is null.</para> <para>Then the method tests the collections items counters equity and
/// returns
/// <c>false</c>
/// when both items counters are different.</para> <para>Finally, the method deepens the comparison to each individual
/// item. It ensures that for the same item position both items are
/// either null, or not null but equals. The method returns
/// <c>false</c>
/// whenever one of both of these conditions is null.</para> <para>By supposing that all items are equals, the method returns
/// <c>true</c>
/// .</para>
/// </remarks>
public static bool Equals(
IEnumerable left,
IEnumerable right)
{
if ((left == null)
&& (right == null))
return true;
if ((left == null)
|| (right == null))
return false;
var leftCount = left is ICollection
? ((ICollection) left).Count
: ToArrayList(left).Count;
var rightList = ToArrayList(right);
if (leftCount != rightList.Count)
return false;
var i = 0;
foreach (var leftItem in left) {
var rightItem = rightList[i];
if ((leftItem != rightItem)
&& ((leftItem == null) || (rightItem == null)))
return false;
else if ((leftItem != null) && (rightItem != null)
&& (!leftItem.Equals(rightItem)))
return false;
++i;
}
return true;
}