|
1 | 1 | using System;
|
2 |
| -using System.Collections; |
3 | 2 | using System.Collections.Generic;
|
4 | 3 | using System.Diagnostics;
|
5 | 4 | using System.Diagnostics.CodeAnalysis;
|
6 | 5 |
|
7 | 6 | namespace PSConsoleUtilities
|
8 | 7 | {
|
| 8 | + internal sealed class QueueDebugView<T> |
| 9 | + { |
| 10 | + private readonly HistoryQueue<T> _queue; |
| 11 | + |
| 12 | + [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] |
| 13 | + public T[] Items |
| 14 | + { |
| 15 | + get { return this._queue.ToArray(); } |
| 16 | + } |
| 17 | + |
| 18 | + public QueueDebugView(HistoryQueue<T> queue) |
| 19 | + { |
| 20 | + if (queue == null) |
| 21 | + throw new ArgumentNullException("queue"); |
| 22 | + this._queue = queue; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + [DebuggerDisplay("Count = {Count}")] |
| 27 | + [DebuggerTypeProxy(typeof(QueueDebugView<>))] |
9 | 28 | internal class HistoryQueue<T>
|
10 | 29 | {
|
11 |
| - private T[] _array; |
| 30 | + private readonly T[] _array; |
12 | 31 | private int _head;
|
13 | 32 | private int _tail;
|
14 | 33 |
|
@@ -72,6 +91,24 @@ public T Dequeue()
|
72 | 91 | return obj;
|
73 | 92 | }
|
74 | 93 |
|
| 94 | + public T[] ToArray() |
| 95 | + { |
| 96 | + var result = new T[Count]; |
| 97 | + if (Count > 0) |
| 98 | + { |
| 99 | + if (_head < _tail) |
| 100 | + { |
| 101 | + Array.Copy(_array, _head, result, 0, Count); |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + Array.Copy(_array, _head, result, 0, _array.Length - _head); |
| 106 | + Array.Copy(_array, 0, result, _array.Length - _head, _tail); |
| 107 | + } |
| 108 | + } |
| 109 | + return result; |
| 110 | + } |
| 111 | + |
75 | 112 | [ExcludeFromCodeCoverage]
|
76 | 113 | public T this[int index]
|
77 | 114 | {
|
|
0 commit comments