10 [DebuggerTypeProxy(typeof(StackDebugView))]
11 [DebuggerDisplay(
"Count = {Count}")]
16 private class SyncStack :
Stack 24 public override object SyncRoot => _root;
26 public override int Count 37 internal SyncStack(
Stack stack)
40 _root = stack.SyncRoot;
43 public override bool Contains(
object obj)
51 public override object Clone()
59 public override void Clear()
67 public override void CopyTo(
Array array,
int arrayIndex)
71 _s.
CopyTo(array, arrayIndex);
75 public override void Push(
object value)
83 public override object Pop()
99 public override object Peek()
107 public override object[]
ToArray()
119 private Stack _stack;
123 private int _version;
125 private object currentElement;
127 public virtual object Current
139 return currentElement;
143 internal StackEnumerator(
Stack stack)
146 _version = _stack._version;
148 currentElement =
null;
151 public object Clone()
153 return MemberwiseClone();
156 public virtual bool MoveNext()
158 if (_version != _stack._version)
165 _index = _stack._size - 1;
166 flag = (_index >= 0);
169 currentElement = _stack._array[_index];
177 flag = (--_index >= 0);
180 currentElement = _stack._array[_index];
184 currentElement =
null;
189 public virtual void Reset()
191 if (_version != _stack._version)
196 currentElement =
null;
200 internal class StackDebugView
205 public object[] Items
209 return stack.ToArray();
213 public StackDebugView(
Stack stack)
223 private object[] _array;
227 private int _version;
230 private object _syncRoot;
232 private const int _defaultCapacity = 10;
249 if (_syncRoot ==
null)
260 _array =
new object[10];
271 if (initialCapacity < 0)
275 if (initialCapacity < 10)
277 initialCapacity = 10;
279 _array =
new object[initialCapacity];
289 : this(col?.
Count ?? 32)
316 Array.
Copy(_array, 0, stack._array, 0, _size);
317 stack._version = _version;
332 if (_array[num] ==
null)
337 else if (_array[num] !=
null && _array[num].Equals(obj))
369 if (array.Length - index < _size)
374 if (array is
object[])
376 object[] array2 = (
object[])array;
377 for (; i < _size; i++)
379 array2[i + index] = _array[_size - i - 1];
384 for (; i < _size; i++)
386 array.SetValue(_array[_size - i - 1], i + index);
395 return new StackEnumerator(
this);
407 return _array[_size - 1];
413 public virtual object Pop()
420 object result = _array[--_size];
421 _array[_size] =
null;
427 public virtual void Push(
object obj)
429 if (_size == _array.Length)
431 object[] array =
new object[2 * _array.Length];
435 _array[_size++] = obj;
444 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true)]
451 return new SyncStack(stack);
458 object[] array =
new object[_size];
459 for (
int i = 0; i < _size; i++)
461 array[i] = _array[_size - i - 1];
virtual object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Collections....
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.Stack is synchronized (thread safe...
bool MoveNext()
Advances the enumerator to the next element of the collection.
Represents a simple last-in-first-out (LIFO) non-generic collection of objects.
virtual void CopyTo(Array array, int index)
Copies the T:System.Collections.Stack to an existing one-dimensional T:System.Array,...
static void Clear(Array array, int index, int length)
Sets a range of elements in an array to the default value of each element type.
virtual object Clone()
Creates a shallow copy of the T:System.Collections.Stack.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
virtual IEnumerator GetEnumerator()
Returns an T:System.Collections.IEnumerator for the T:System.Collections.Stack.
static Stack Synchronized(Stack stack)
Returns a synchronized (thread safe) wrapper for the T:System.Collections.Stack.
virtual object [] ToArray()
Copies the T:System.Collections.Stack to a new array.
Stack(int initialCapacity)
Initializes a new instance of the T:System.Collections.Stack class that is empty and has the specifie...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Provides information about, and means to manipulate, the current environment and platform....
virtual object Peek()
Returns the object at the top of the T:System.Collections.Stack without removing it.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
object Current
Gets the element in the collection at the current position of the enumerator.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
virtual object Pop()
Removes and returns the object at the top of the T:System.Collections.Stack.
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
The exception that is thrown when one of the arguments provided to a method is not valid.
Stack()
Initializes a new instance of the T:System.Collections.Stack class that is empty and has the default ...
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
virtual void Clear()
Removes all objects from the T:System.Collections.Stack.
Specifies that the class can be serialized.
virtual int Count
Gets the number of elements contained in the T:System.Collections.Stack.
The exception that is thrown when a method call is invalid for the object's current state.
virtual void Push(object obj)
Inserts an object at the top of the T:System.Collections.Stack.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
DebuggerBrowsableState
Provides display instructions for the debugger.
Provides atomic operations for variables that are shared by multiple threads.
Supports a simple iteration over a non-generic collection.
virtual bool Contains(object obj)
Determines whether an element is in the T:System.Collections.Stack.