Merge pull request #733 from amoiseev-softheme/bugfix/monofix
[mono.git] / mcs / class / System / System.Collections.Generic / Stack.cs
index 5fa60de093a33746be0a46436f1c58dd2eb83e4f..4a693549b5f6c8636fd2824a3590b6bbf22d17b8 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System;
 using System.Runtime.InteropServices;
+using System.Diagnostics;
 
 namespace System.Collections.Generic
 {
        [ComVisible (false)]
        [Serializable]
+       [DebuggerDisplay ("Count={Count}")]
+       [DebuggerTypeProxy (typeof (CollectionDebuggerView))]
        public class Stack <T> : IEnumerable <T>, ICollection, IEnumerable
        {
                T [] _array;
@@ -51,12 +53,12 @@ namespace System.Collections.Generic
                {
                }
                
-               public Stack (int count)
+               public Stack (int capacity)
                {
-                       if (count < 0)
-                               throw new ArgumentOutOfRangeException ("count");
+                       if (capacity < 0)
+                               throw new ArgumentOutOfRangeException ("capacity");
 
-                       _array = new T [count];
+                       _array = new T [capacity];
                }
                
                public Stack (IEnumerable <T> collection)
@@ -85,17 +87,22 @@ namespace System.Collections.Generic
                        _version ++;
                }
                
-               public bool Contains (T t)
+               public bool Contains (T item)
                {               
-                       return _array != null && Array.IndexOf (_array, t, 0, _size) != -1;
+                       return _array != null && Array.IndexOf (_array, item, 0, _size) != -1;
                }
                
-               public void CopyTo (T [] dest, int idx)
+               public void CopyTo (T [] array, int arrayIndex)
                {
+                       if (array == null)
+                               throw new ArgumentNullException ("array");
+                       if (arrayIndex < 0)
+                               throw new ArgumentOutOfRangeException ("idx");
+                       
                        // this gets copied in the order that it is poped
                        if (_array != null) {
-                               Array.Copy (_array, 0, dest, idx, _size);
-                               Array.Reverse (dest, idx, _size);
+                               Array.Copy (_array, 0, array, arrayIndex, _size);
+                               Array.Reverse (array, arrayIndex, _size);
                        }
                }
                
@@ -119,14 +126,14 @@ namespace System.Collections.Generic
                        return popped;
                }
 
-               public void Push (T t)
+               public void Push (T item)
                {
-                       if (_size == 0 || _size == _array.Length)
+                       if (_array == null || _size == _array.Length)
                                Array.Resize <T> (ref _array, _size == 0 ? INITIAL_SIZE : 2 * _size);
                        
                        _version ++;
                        
-                       _array [_size++] = t;
+                       _array [_size++] = item;
                }
                
                public T [] ToArray ()
@@ -159,7 +166,7 @@ namespace System.Collections.Generic
                {
                        try {
                                if (_array != null) {
-                                       _array.CopyTo (dest, idx);
+                                       Array.Copy (_array, 0, dest, idx, _size);
                                        Array.Reverse (dest, idx, _size);
                                }
                        } catch (ArrayTypeMismatchException) {
@@ -206,7 +213,7 @@ namespace System.Collections.Generic
                        // broken.
                        public void Dispose ()
                        {
-                               idx = NOT_STARTED;
+                               idx = FINISHED;
                        }
                        
                        public bool MoveNext ()
@@ -244,4 +251,3 @@ namespace System.Collections.Generic
                }
        }
 }
-#endif