[ComVisible (true)]
// FIXME: We are doing way to many double/triple exception checks for the overloaded functions"
public abstract class Array : ICloneable, ICollection, IList, IEnumerable
-#if NET_4_0
, IStructuralComparable, IStructuralEquatable
-#endif
{
// Constructor
private Array ()
Copy (this, this.GetLowerBound (0), array, index, this.GetLength (0));
}
-#if NET_4_5
internal T InternalArray__IReadOnlyList_get_Item<T> (int index)
{
if (unchecked ((uint) index) >= unchecked ((uint) Length))
{
return Length;
}
-#endif
internal void InternalArray__Insert<T> (int index, T item)
{
return new SimpleEnumerator (this);
}
-#if NET_4_0
int IStructuralComparable.CompareTo (object other, IComparer comparer)
{
if (other == null)
hash = ((hash << 7) + hash) ^ comparer.GetHashCode (GetValueImpl (i));
return hash;
}
-#endif
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
public int GetUpperBound (int dimension)
SetValue (value, ind);
}
+ internal static Array UnsafeCreateInstance (Type elementType, int length)
+ {
+ return CreateInstance (elementType, length);
+ }
+
+ internal static Array UnsafeCreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
+ {
+ return CreateInstance(elementType, lengths, lowerBounds);
+ }
+
+ internal static Array UnsafeCreateInstance (Type elementType, int length1, int length2)
+ {
+ return CreateInstance (elementType, length1, length2);
+ }
+
+ internal static Array UnsafeCreateInstance (Type elementType, params int[] lengths)
+ {
+ return CreateInstance(elementType, lengths);
+ }
+
public static Array CreateInstance (Type elementType, int length)
{
int[] lengths = {length};
int[] bounds = null;
- elementType = elementType.UnderlyingSystemType;
- if (!elementType.IsSystemType)
+ elementType = elementType.UnderlyingSystemType as RuntimeType;
+ if (elementType == null)
throw new ArgumentException ("Type must be a type provided by the runtime.", "elementType");
if (elementType.Equals (typeof (void)))
throw new NotSupportedException ("Array type can not be void");
if (lowerBounds == null)
throw new ArgumentNullException ("lowerBounds");
- elementType = elementType.UnderlyingSystemType;
- if (!elementType.IsSystemType)
+ elementType = elementType.UnderlyingSystemType as RuntimeType;
+ if (elementType == null)
throw new ArgumentException ("Type must be a type provided by the runtime.", "elementType");
if (elementType.Equals (typeof (void)))
throw new NotSupportedException ("Array type can not be void");
int source_pos = sourceIndex - sourceArray.GetLowerBound (0);
int dest_pos = destinationIndex - destinationArray.GetLowerBound (0);
+ if (dest_pos < 0)
+ throw new ArgumentOutOfRangeException ("destinationIndex", "Index was less than the array's lower bound in the first dimension.");
+
// re-ordered to avoid possible integer overflow
if (source_pos > sourceArray.Length - length)
throw new ArgumentException ("length");
[ReliabilityContractAttribute (Consistency.MayCorruptInstance, Cer.MayFail)]
public static void Copy (Array sourceArray, long sourceIndex, Array destinationArray,
- long destinationIndex, long length)
+ long destinationIndex, long length)
{
if (sourceArray == null)
throw new ArgumentNullException ("sourceArray");
if (keys == null)
throw new ArgumentNullException ("keys");
-
- if (keys.Length != items.Length)
- throw new ArgumentException ("Length of keys and items does not match.");
-
+
+ if (keys.Length > items.Length)
+ throw new ArgumentException ("Length of keys is larger than length of items.");
+
SortImpl<TKey, TValue> (keys, items, 0, keys.Length, comparer);
}
public object Current {
get {
- // Exception messages based on MS implementation
+ // Exception messages based on MS implementation
if (currentpos < 0 )
throw new InvalidOperationException (Locale.GetText (
"Enumeration has not started."));
if (count < 0 || startIndex < array.GetLowerBound (0) || startIndex - 1 > array.GetUpperBound (0) - count)
throw new ArgumentOutOfRangeException ();
- return EqualityComparer<T>.Default.IndexOf (array, value, startIndex, startIndex + count);
+ return EqualityComparer<T>.Default.IndexOf (array, value, startIndex, count);
}
public static int LastIndexOf<T> (T [] array, T value)
return d;
}
+ [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
+ public static T[] Empty<T>()
+ {
+ return EmptyArray<T>.Value;
+ }
+
public static bool Exists<T> (T [] array, Predicate <T> match)
{
if (array == null)
//
// Moved value from instance into target of different type with no checks (JIT intristics)
//
+ // Restrictions:
+ //
+ // S and R must either:
+ // both be blitable valuetypes
+ // both be reference types (IOW, an unsafe cast)
+ // S and R cannot be float or double
+ // S and R must either:
+ // both be a struct
+ // both be a scalar
+ // S and R must either:
+ // be of same size
+ // both be a scalar of size <= 4
+ //
internal static R UnsafeMov<S,R> (S instance) {
return (R)(object) instance;
}
#endregion
+
+ internal sealed class FunctorComparer<T> : IComparer<T> {
+ Comparison<T> comparison;
+
+ public FunctorComparer(Comparison<T> comparison) {
+ this.comparison = comparison;
+ }
+
+ public int Compare(T x, T y) {
+ return comparison(x, y);
+ }
+ }
}
}