diff options
Diffstat (limited to 'src/mscorlib/src/System/Array.cs')
-rw-r--r-- | src/mscorlib/src/System/Array.cs | 93 |
1 files changed, 5 insertions, 88 deletions
diff --git a/src/mscorlib/src/System/Array.cs b/src/mscorlib/src/System/Array.cs index 7bb6ebbdd3..23989f30fb 100644 --- a/src/mscorlib/src/System/Array.cs +++ b/src/mscorlib/src/System/Array.cs @@ -20,13 +20,11 @@ namespace System { using System.Runtime.Versioning; using System.Security; using System.Diagnostics; - using System.Security.Permissions; using System.Diagnostics.Contracts; // Note that we make a T[] (single-dimensional w/ zero as the lower bound) implement both // IList<U> and IReadOnlyList<U>, where T : U dynamically. See the SZArrayHelper class for details. [Serializable] - [ComVisible(true)] public abstract class Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable { // This ctor exists solely to prevent C# from generating a protected .ctor that violates the surface area. I really want this to be a @@ -43,7 +41,6 @@ namespace System { return new ReadOnlyCollection<T>(array); } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static void Resize<T>(ref T[] array, int newSize) { if (newSize < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.newSize, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); @@ -154,7 +151,7 @@ namespace System { if (lengths[i] < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); - fixed (int* pLengths = lengths) + fixed (int* pLengths = &lengths[0]) return InternalCreate((void*)t.TypeHandle.Value,lengths.Length,pLengths,null); } @@ -211,8 +208,8 @@ namespace System { if (lengths[i] < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); - fixed (int* pLengths = lengths) - fixed(int* pLowerBounds = lowerBounds) + fixed (int* pLengths = &lengths[0]) + fixed(int* pLowerBounds = &lowerBounds[0]) return InternalCreate((void*)t.TypeHandle.Value,lengths.Length,pLengths,pLowerBounds); } @@ -224,25 +221,9 @@ namespace System { return CreateInstance(elementType, length); } - 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); - } - - internal static Array UnsafeCreateInstance(Type elementType, int[] lengths, int[] lowerBounds) - { - return CreateInstance(elementType, lengths, lowerBounds); - } - // Copies length elements from sourceArray, starting at index 0, to // destinationArray, starting at index 0. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Copy(Array sourceArray, Array destinationArray, int length) { if (sourceArray == null) @@ -263,7 +244,6 @@ namespace System { // Copies length elements from sourceArray, starting at sourceIndex, to // destinationArray, starting at destinationIndex. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length) { Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, false); @@ -273,7 +253,6 @@ namespace System { // instance & might fail when called from within a CER, or if the // reliable flag is true, it will either always succeed or always // throw an exception with no side effects. - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable); @@ -282,13 +261,11 @@ namespace System { // compatible array types based on the array element type - this // method does not support casting, boxing, or primitive widening. // It will up-cast, assuming the array types are correct. - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static void ConstrainedCopy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length) { Copy(sourceArray, sourceIndex, destinationArray, destinationIndex, length, true); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Copy(Array sourceArray, Array destinationArray, long length) { if (length > Int32.MaxValue || length < Int32.MinValue) @@ -297,7 +274,6 @@ namespace System { Array.Copy(sourceArray, destinationArray, (int) length); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length) { if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) @@ -315,7 +291,6 @@ namespace System { // at index. // [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static extern void Clear(Array array, int index, int length); // The various Get values... @@ -328,7 +303,7 @@ namespace System { Contract.EndContractBlock(); TypedReference elemref = new TypedReference(); - fixed(int* pIndices = indices) + fixed(int* pIndices = &indices[0]) InternalGetReference(&elemref, indices.Length, pIndices); return TypedReference.InternalToObject(&elemref); } @@ -375,7 +350,6 @@ namespace System { return TypedReference.InternalToObject(&elemref); } - [ComVisible(false)] public Object GetValue(long index) { if (index > Int32.MaxValue || index < Int32.MinValue) @@ -385,7 +359,6 @@ namespace System { return this.GetValue((int) index); } - [ComVisible(false)] public Object GetValue(long index1, long index2) { if (index1 > Int32.MaxValue || index1 < Int32.MinValue) @@ -397,7 +370,6 @@ namespace System { return this.GetValue((int) index1, (int) index2); } - [ComVisible(false)] public Object GetValue(long index1, long index2, long index3) { if (index1 > Int32.MaxValue || index1 < Int32.MinValue) @@ -411,7 +383,6 @@ namespace System { return this.GetValue((int) index1, (int) index2, (int) index3); } - [ComVisible(false)] public Object GetValue(params long[] indices) { if (indices == null) @@ -485,12 +456,11 @@ namespace System { Contract.EndContractBlock(); TypedReference elemref = new TypedReference(); - fixed(int* pIndices = indices) + fixed(int* pIndices = &indices[0]) InternalGetReference(&elemref, indices.Length, pIndices); InternalSetValue(&elemref,value); } - [ComVisible(false)] public void SetValue(Object value, long index) { if (index > Int32.MaxValue || index < Int32.MinValue) @@ -500,7 +470,6 @@ namespace System { this.SetValue(value, (int) index); } - [ComVisible(false)] public void SetValue(Object value, long index1, long index2) { if (index1 > Int32.MaxValue || index1 < Int32.MinValue) @@ -512,7 +481,6 @@ namespace System { this.SetValue(value, (int) index1, (int) index2); } - [ComVisible(false)] public void SetValue(Object value, long index1, long index2, long index3) { if (index1 > Int32.MaxValue || index1 < Int32.MinValue) @@ -526,7 +494,6 @@ namespace System { this.SetValue(value, (int) index1, (int) index2, (int) index3); } - [ComVisible(false)] public void SetValue(Object value, params long[] indices) { if (indices == null) @@ -559,12 +526,10 @@ namespace System { public extern int Length { [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [MethodImpl(MethodImplOptions.InternalCall)] get; } - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static int GetMedian(int low, int hi) { // Note both may be negative, if we are dealing with arrays w/ negative lower bounds. Contract.Requires(low <= hi); @@ -580,10 +545,8 @@ namespace System { internal const int MaxArrayLength = 0X7FEFFFFF; internal const int MaxByteArrayLength = 0x7FFFFFC7; - [ComVisible(false)] public extern long LongLength { [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [MethodImpl(MethodImplOptions.InternalCall)] get; } @@ -593,7 +556,6 @@ namespace System { public extern int GetLength(int dimension); [Pure] - [ComVisible(false)] public long GetLongLength(int dimension) { //This method should throw an IndexOufOfRangeException for compat if dimension < 0 or >= Rank return GetLength(dimension); @@ -601,22 +563,18 @@ namespace System { public extern int Rank { [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [MethodImplAttribute(MethodImplOptions.InternalCall)] get; } [Pure] [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public extern int GetUpperBound(int dimension); [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern int GetLowerBound(int dimension); - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [MethodImplAttribute(MethodImplOptions.InternalCall)] internal extern int GetDataPtrOffsetInternal(); @@ -783,7 +741,6 @@ namespace System { // is larger than the given search value. // [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, Object value) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -807,7 +764,6 @@ namespace System { // is larger than the given search value. // [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, int index, int length, Object value) { return BinarySearch(array, index, length, value, null); } @@ -827,7 +783,6 @@ namespace System { // is larger than the given search value. // [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, Object value, IComparer comparer) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -852,7 +807,6 @@ namespace System { // is larger than the given search value. // [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch(Array array, int index, int length, Object value, IComparer comparer) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -923,11 +877,9 @@ namespace System { } [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] private static extern bool TrySZBinarySearch(Array sourceArray, int sourceIndex, int count, Object value, out int retVal); [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch<T>(T[] array, T value) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -936,7 +888,6 @@ namespace System { } [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch<T>(T[] array, T value, System.Collections.Generic.IComparer<T> comparer) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -945,13 +896,11 @@ namespace System { } [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch<T>(T[] array, int index, int length, T value) { return BinarySearch<T>(array, index, length, value, null); } [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int BinarySearch<T>(T[] array, int index, int length, T value, System.Collections.Generic.IComparer<T> comparer) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1004,7 +953,6 @@ namespace System { } [Pure] - [ComVisible(false)] public void CopyTo(Array array, long index) { if (index > Int32.MaxValue || index < Int32.MinValue) @@ -1015,7 +963,6 @@ namespace System { } [Pure] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static T[] Empty<T>() { Contract.Ensures(Contract.Result<T[]>() != null); @@ -1253,7 +1200,6 @@ namespace System { // The array is searched forwards, and the elements of the array are // compared to the given value using the Object.Equals method. // - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int IndexOf(Array array, Object value) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1269,7 +1215,6 @@ namespace System { // elements of the array are compared to the given value using the // Object.Equals method. // - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int IndexOf(Array array, Object value, int startIndex) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1285,7 +1230,6 @@ namespace System { // elements of the array are compared to the given value using the // Object.Equals method. // - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int IndexOf(Array array, Object value, int startIndex, int count) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1380,7 +1324,6 @@ namespace System { } [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] private static extern bool TrySZIndexOf(Array sourceArray, int sourceIndex, int count, Object value, out int retVal); @@ -1388,7 +1331,6 @@ namespace System { // The array is searched backwards, and the elements of the array are // compared to the given value using the Object.Equals method. // - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int LastIndexOf(Array array, Object value) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1403,7 +1345,6 @@ namespace System { // startIndex and ending at index 0. The elements of the array are // compared to the given value using the Object.Equals method. // - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int LastIndexOf(Array array, Object value, int startIndex) { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1419,7 +1360,6 @@ namespace System { // the array are compared to the given value using the Object.Equals // method. // - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public static int LastIndexOf(Array array, Object value, int startIndex, int count) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1531,7 +1471,6 @@ namespace System { } [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] private static extern bool TrySZLastIndexOf(Array sourceArray, int sourceIndex, int count, Object value, out int retVal); @@ -1540,7 +1479,6 @@ namespace System { // located at index length - i - 1, where length is the // length of the array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Reverse(Array array) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1554,7 +1492,6 @@ namespace System { // index index + (index + count - i - 1). // Reliability note: This may fail because it may have to box objects. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Reverse(Array array, int index, int length) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1598,10 +1535,8 @@ namespace System { } [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] private static extern bool TrySZReverse(Array array, int index, int count); - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Reverse<T>(T[] array) { if (array == null) @@ -1610,7 +1545,6 @@ namespace System { Reverse(array, 0, array.Length); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Reverse<T>(T[] array, int index, int length) { if (array == null) @@ -1639,7 +1573,6 @@ namespace System { // other using the IComparable interface, which must be implemented // by all elements of the array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array array) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1653,7 +1586,6 @@ namespace System { // keys to each other using the IComparable interface, which must be // implemented by all elements of the keys array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items) { if (keys==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); @@ -1665,7 +1597,6 @@ namespace System { // elements to each other using the IComparable interface, which // must be implemented by all elements in the given section of the array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array array, int index, int length) { Sort(array, null, index, length, null); } @@ -1676,7 +1607,6 @@ namespace System { // keys to each other using the IComparable interface, which must be // implemented by all elements of the keys array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items, int index, int length) { Sort(keys, items, index, length, null); } @@ -1687,7 +1617,6 @@ namespace System { // IComparable interface, which in that case must be implemented by // all elements of the array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array array, IComparer comparer) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1703,7 +1632,6 @@ namespace System { // the IComparable interface, which in that case must be implemented // by all elements of the keys array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items, IComparer comparer) { if (keys==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); @@ -1717,7 +1645,6 @@ namespace System { // the IComparable interface, which in that case must be implemented // by all elements in the given section of the array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array array, int index, int length, IComparer comparer) { Sort(array, null, index, length, comparer); } @@ -1730,7 +1657,6 @@ namespace System { // the IComparable interface, which in that case must be implemented // by all elements of the given section of the keys array. // - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort(Array keys, Array items, int index, int length, IComparer comparer) { if (keys==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); @@ -1772,10 +1698,8 @@ namespace System { } [MethodImplAttribute(MethodImplOptions.InternalCall)] - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] private static extern bool TrySZSort(Array keys, Array items, int left, int right); - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<T>(T[] array) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1783,7 +1707,6 @@ namespace System { Sort<T>(array, 0, array.Length, null); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items) { if (keys==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); @@ -1791,17 +1714,14 @@ namespace System { Sort<TKey, TValue>(keys, items, 0, keys.Length, null); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<T>(T[] array, int index, int length) { Sort<T>(array, index, length, null); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length) { Sort<TKey, TValue>(keys, items, index, length, null); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<T>(T[] array, System.Collections.Generic.IComparer<T> comparer) { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1809,7 +1729,6 @@ namespace System { Sort<T>(array, 0, array.Length, comparer); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, System.Collections.Generic.IComparer<TKey> comparer) { if (keys==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); @@ -1817,7 +1736,6 @@ namespace System { Sort<TKey, TValue>(keys, items, 0, keys.Length, comparer); } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<T>(T[] array, int index, int length, System.Collections.Generic.IComparer<T> comparer) { if (array==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); @@ -1840,7 +1758,6 @@ namespace System { } } - [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] public static void Sort<TKey, TValue>(TKey[] keys, TValue[] items, int index, int length, System.Collections.Generic.IComparer<TKey> comparer) { if (keys==null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); |