-//
+
// System.Array.cs
//
// Authors:
}
// IList interface
- public object this [int index] {
+ object IList.this [int index] {
get {
return GetValueImpl (index);
}
}
bool IList.Contains (object value) {
+ if (this.Rank > 1)
+ throw new RankException ("Only single dimension arrays are supported.");
+
int length = this.Length;
for (int i = 0; i < length; i++) {
if (value.Equals (this.GetValueImpl (i)))
internal extern static Array CreateInstanceImpl(Type elementType, int[] lengths, int [] bounds);
// Properties
- public virtual int Count {
+ int ICollection.Count {
get {
return Length;
}
public static int BinarySearch (Array array, object value)
{
+ if (array == null)
+ throw new ArgumentNullException("array");
+
+ if (array.Rank > 1)
+ throw new RankException();
+
+ if (!(value is IComparable))
+ throw new ArgumentException("value does not support IComparable");
+
return BinarySearch (array, array.GetLowerBound (0), array.GetLength (0),
value, null);
}
public static int BinarySearch (Array array, object value, IComparer comparer)
{
+ if (array == null)
+ throw new ArgumentNullException("array");
+
+ if (array.Rank > 1)
+ throw new RankException();
+
+ if ((comparer == null) && !(value is IComparable))
+ throw new ArgumentException("comparer is null and value does not support IComparable");
+
return BinarySearch (array, array.GetLowerBound (0), array.GetLength (0),
value, comparer);
}
public static int BinarySearch (Array array, int index, int length, object value)
{
+ if (array == null)
+ throw new ArgumentNullException("array");
+
+ if (array.Rank > 1)
+ throw new RankException();
+
+ if (index < array.GetLowerBound (0))
+ throw new ArgumentOutOfRangeException("index is less than the lower bound of array.");
+ if (length < 0)
+ throw new ArgumentOutOfRangeException("length is less than zero.");
+
+ if (index + length > array.GetLowerBound (0) + array.GetLength (0))
+ throw new ArgumentException("index and length do not specify a valid range in array.");
+ if (!(value is IComparable))
+ throw new ArgumentException("value does not support IComparable");
+
return BinarySearch (array, index, length, value, null);
}
if (array.Rank > 1)
throw new RankException ();
- if (index < array.GetLowerBound (0) || length < 0)
- throw new ArgumentOutOfRangeException ("index");
+ if (index < array.GetLowerBound (0))
+ throw new ArgumentOutOfRangeException("index is less than the lower bound of array.");
+ if (length < 0)
+ throw new ArgumentOutOfRangeException("length is less than zero.");
- if (index + length > array.GetUpperBound (0) + 1)
- throw new ArgumentException ("length");
+ if (index + length > array.GetLowerBound (0) + array.GetLength (0))
+ throw new ArgumentException("index and length do not specify a valid range in array.");
+
+ if ((comparer == null) && !(value is IComparable))
+ throw new ArgumentException("comparer is null and value does not support IComparable");
// cache this in case we need it
IComparable valueCompare = value as IComparable;
while (iMin < iMax)
{
int iMid = (iMin + iMax) / 2;
- object elt = array.GetValue (iMid);
+ object elt = array.GetValueImpl (iMid);
// this order is from MSDN
if (comparer != null)
for (int i = 0; i < length; i++)
{
- array.SetValue(null, index + i);
+ array.SetValueImpl(null, index + i);
}
}
public static void Copy (Array source, Array dest, int length)
{
+ // need these checks here because we are going to use
+ // GetLowerBound() on source and dest.
+ if (source == null)
+ throw new ArgumentNullException ("null");
+
+ if (dest == null)
+ throw new ArgumentNullException ("dest");
+
Copy (source, source.GetLowerBound (0), dest, dest.GetLowerBound (0), length);
}
for (int i = 0; i < length; i++)
{
- if (array.GetValue(index + i).Equals(value))
+ if (array.GetValueImpl(index + i).Equals(value))
return index + i;
}
for (int i = index; i >= index-length+1; i--)
{
- if (array.GetValue(i).Equals(value))
+ if (array.GetValueImpl(i).Equals(value))
return i;
}
{
object tmp;
- tmp = array.GetValue (index + i);
- array.SetValue(array.GetValue (index + length - i - 1), index + i);
- array.SetValue(tmp, index + length - i - 1);
+ tmp = array.GetValueImpl (index + i);
+ array.SetValueImpl(array.GetValueImpl (index + length - i - 1), index + i);
+ array.SetValueImpl(tmp, index + length - i - 1);
}
}
int low = low0;
int high = high0;
- object objPivot = keys.GetValue ((low + high) / 2);
+ object objPivot = keys.GetValueImpl ((low + high) / 2);
while (low <= high)
{
// Move the walls in
- while (low < high0 && compare (keys.GetValue (low), objPivot, comparer) < 0)
+ while (low < high0 && compare (keys.GetValueImpl (low), objPivot, comparer) < 0)
++low;
- while (high > low0 && compare (objPivot, keys.GetValue (high), comparer) < 0)
+ while (high > low0 && compare (objPivot, keys.GetValueImpl (high), comparer) < 0)
--high;
if (low <= high)
{
object tmp;
- tmp = keys.GetValue (i);
- keys.SetValue (keys.GetValue (j), i);
- keys.SetValue (tmp, j);
+ tmp = keys.GetValueImpl (i);
+ keys.SetValueImpl (keys.GetValue (j), i);
+ keys.SetValueImpl (tmp, j);
if (items != null)
{
- tmp = items.GetValue (i);
- items.SetValue (items.GetValue (j), i);
- items.SetValue (tmp, j);
+ tmp = items.GetValueImpl (i);
+ items.SetValueImpl (items.GetValueImpl (j), i);
+ items.SetValueImpl (tmp, j);
}
}