Author: miguel
Date: 2007-01-14 18:16:49 -0500 (Sun, 14 Jan 2007)
New Revision: 70997
Modified:
trunk/mcs/class/corlib/System/ArraySegment.cs
trunk/mcs/class/corlib/System/ChangeLog
trunk/mcs/class/corlib/Test/System/ArraySegmentTest.cs
trunk/mcs/class/corlib/Test/System/ChangeLog
Log:
2007-01-14 Jensen Somers <[EMAIL PROTECTED]>
* ArraySegment.cs: Added Equals() method, operator == and !=
overloading and GetHashCode().
2007-01-14 Jensen Somers <[EMAIL PROTECTED]>
* ArraySegmentTest.cs: Add a test case for the ArraySegment.Equals
functionality.
Modified: trunk/mcs/class/corlib/System/ArraySegment.cs
===================================================================
--- trunk/mcs/class/corlib/System/ArraySegment.cs 2007-01-14 22:02:00 UTC
(rev 70996)
+++ trunk/mcs/class/corlib/System/ArraySegment.cs 2007-01-14 23:16:49 UTC
(rev 70997)
@@ -3,6 +3,7 @@
//
// Authors:
// Ben Maurer ([EMAIL PROTECTED])
+// Jensen Somers <[EMAIL PROTECTED]>
//
// Copyright (C) 2004 Novell
//
@@ -77,6 +78,36 @@
public int Count {
get { return count; }
}
+
+ public override bool Equals (Object obj)
+ {
+ if (obj is ArraySegment<T>) {
+ return this.Equals((ArraySegment<T>) obj);
+ }
+ return false;
+ }
+
+ public bool Equals (ArraySegment<T> obj)
+ {
+ if ((this.array == obj.Array) && (this.offset ==
obj.Offset) && (this.count == obj.Count))
+ return true;
+ return false;
+ }
+
+ public override int GetHashCode ()
+ {
+ return ((this.array.GetHashCode() ^ this.offset) ^
this.count);
+ }
+
+ public static bool operator ==(ArraySegment<T> a,
ArraySegment<T> b)
+ {
+ return a.Equals(b);
+ }
+
+ public static bool operator !=(ArraySegment<T> a,
ArraySegment<T> b)
+ {
+ return !(a.Equals(b));
+ }
}
}
#endif
Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog 2007-01-14 22:02:00 UTC (rev
70996)
+++ trunk/mcs/class/corlib/System/ChangeLog 2007-01-14 23:16:49 UTC (rev
70997)
@@ -1,3 +1,8 @@
+2007-01-14 Jensen Somers <[EMAIL PROTECTED]>
+
+ * ArraySegment.cs: Added Equals() method, operator == and !=
+ overloading and GetHashCode().
+
2007-01-10 Andy Hume <[EMAIL PROTECTED]>
* Fixes to a number of exception classes.
Modified: trunk/mcs/class/corlib/Test/System/ArraySegmentTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/ArraySegmentTest.cs 2007-01-14
22:02:00 UTC (rev 70996)
+++ trunk/mcs/class/corlib/Test/System/ArraySegmentTest.cs 2007-01-14
23:16:49 UTC (rev 70997)
@@ -2,6 +2,7 @@
//
// Ankit Jain <[EMAIL PROTECTED]>
// Raja R Harinath <[EMAIL PROTECTED]>
+// Jensen Somers <[EMAIL PROTECTED]>
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
@@ -136,8 +137,27 @@
{
ArraySegment<byte> seg = new ArraySegment<byte> (null);
}
-
-
+
+ [Test]
+ public void TestArraySegmentEqual ()
+ {
+ string[] myArr_1 = { "The", "good" };
+ string[] myArr_2 = { "The", "good" };
+
+ ArraySegment<string> myArrSeg_1 = new ArraySegment<string>(myArr_1);
+ ArraySegment<string> myArrSeg_2 = new ArraySegment<string>(myArr_2);
+
+ // Should return true.
+ Assert.AreEqual(myArrSeg_1.Equals(myArrSeg_1), true);
+ Assert.AreEqual(myArrSeg_1 == myArrSeg_1, true);
+
+ // Should return false. Allthough the strings are the same.
+ Assert.AreEqual(myArrSeg_1.Equals(myArrSeg_2), false);
+ Assert.AreEqual(myArrSeg_1 == myArrSeg_2, false);
+
+ // Should return true.
+ Assert.AreEqual(myArrSeg_1 != myArrSeg_2, true);
+ }
}
}
Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog 2007-01-14 22:02:00 UTC
(rev 70996)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog 2007-01-14 23:16:49 UTC
(rev 70997)
@@ -1,3 +1,8 @@
+2007-01-14 Jensen Somers <[EMAIL PROTECTED]>
+
+ * ArraySegmentTest.cs: Add a test case for the ArraySegment.Equals
+ functionality.
+
2006-12-30 Alp Toker <[EMAIL PROTECTED]>
* MathTest.cs: Add test case for new (2.0) Decimal.Ceiling.
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches