Skip to content

Commit 90859a9

Browse files
committed
Make displaying history in debugger simpler
1 parent 24a76b5 commit 90859a9

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

PSReadLine/HistoryQueue.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Diagnostics;
54
using System.Diagnostics.CodeAnalysis;
65

76
namespace PSConsoleUtilities
87
{
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<>))]
928
internal class HistoryQueue<T>
1029
{
11-
private T[] _array;
30+
private readonly T[] _array;
1231
private int _head;
1332
private int _tail;
1433

@@ -72,6 +91,24 @@ public T Dequeue()
7291
return obj;
7392
}
7493

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+
75112
[ExcludeFromCodeCoverage]
76113
public T this[int index]
77114
{

0 commit comments

Comments
 (0)