Merge pull request #3662 from henricm/fix-windowsbase-on-win
[mono.git] / mcs / class / corlib / System / Array.cs
index ab97679e4f0ffbf3f857656ca2161f936b5803c6..8f6e0aa098e40b238d2738503705207086c3eb80 100644 (file)
@@ -653,6 +653,21 @@ namespace System
                        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};
@@ -686,8 +701,8 @@ namespace System
 
                        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");
@@ -710,8 +725,8 @@ namespace System
                        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");
@@ -1674,10 +1689,10 @@ namespace System
                
                        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);
                }
 
@@ -3030,7 +3045,7 @@ namespace System
                        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)
@@ -3087,6 +3102,12 @@ namespace System
                        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)
@@ -3168,6 +3189,19 @@ namespace System
                //
                // 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;
                }