Skip to content

Commit c362923

Browse files
stephentoubsafern
authored andcommitted
Add some DebuggerDisplay attributes in System.Linq (dotnet/corefx#41386)
Commit migrated from dotnet/corefx@e667c29
1 parent 69feffc commit c362923

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace System.Linq
1717
/// Returning an instance of this type is useful to quickly handle scenarios where it is known
1818
/// that an operation will result in zero elements.
1919
/// </remarks>
20+
[DebuggerDisplay("Count = 0")]
2021
internal sealed class EmptyPartition<TElement> : IPartition<TElement>, IEnumerator<TElement>
2122
{
2223
/// <summary>
@@ -150,6 +151,7 @@ public static partial class Enumerable
150151
/// An iterator that yields the items of part of an <see cref="IList{TSource}"/>.
151152
/// </summary>
152153
/// <typeparam name="TSource">The type of the source list.</typeparam>
154+
[DebuggerDisplay("Count = {Count}")]
153155
private sealed class ListPartition<TSource> : Iterator<TSource>, IPartition<TSource>
154156
{
155157
private readonly IList<TSource> _source;

src/libraries/System.Linq/src/System/Linq/Range.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static IEnumerable<int> Range(int start, int count)
2828
/// <summary>
2929
/// An iterator that yields a range of consecutive integers.
3030
/// </summary>
31+
[DebuggerDisplay("Count = {CountForDebugger}")]
3132
private sealed partial class RangeIterator : Iterator<int>
3233
{
3334
private readonly int _start;
@@ -40,6 +41,8 @@ public RangeIterator(int start, int count)
4041
_end = unchecked(start + count);
4142
}
4243

44+
private int CountForDebugger => _end - _start;
45+
4346
public override Iterator<int> Clone() => new RangeIterator(_start, _end - _start);
4447

4548
public override bool MoveNext()

src/libraries/System.Linq/src/System/Linq/Repeat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static IEnumerable<TResult> Repeat<TResult>(TResult element, int count)
2828
/// An iterator that yields the same item multiple times.
2929
/// </summary>
3030
/// <typeparam name="TResult">The type of the item.</typeparam>
31+
[DebuggerDisplay("Count = {_count}")]
3132
private sealed partial class RepeatIterator<TResult> : Iterator<TResult>
3233
{
3334
private readonly int _count;

src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ public int GetCount(bool onlyIfCheap)
683683
/// </summary>
684684
/// <typeparam name="TSource">The type of the source list.</typeparam>
685685
/// <typeparam name="TResult">The type of the mapped items.</typeparam>
686+
[DebuggerDisplay("Count = {Count}")]
686687
private sealed class SelectListPartitionIterator<TSource, TResult> : Iterator<TResult>, IPartition<TResult>
687688
{
688689
private readonly IList<TSource> _source;

src/libraries/System.Linq/src/System/Linq/Select.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> s
156156
/// </summary>
157157
/// <typeparam name="TSource">The type of the source array.</typeparam>
158158
/// <typeparam name="TResult">The type of the mapped items.</typeparam>
159+
[DebuggerDisplay("Count = {CountForDebugger}")]
159160
private sealed partial class SelectArrayIterator<TSource, TResult> : Iterator<TResult>
160161
{
161162
private readonly TSource[] _source;
@@ -170,6 +171,8 @@ public SelectArrayIterator(TSource[] source, Func<TSource, TResult> selector)
170171
_selector = selector;
171172
}
172173

174+
private int CountForDebugger => _source.Length;
175+
173176
public override Iterator<TResult> Clone() => new SelectArrayIterator<TSource, TResult>(_source, _selector);
174177

175178
public override bool MoveNext()
@@ -194,6 +197,7 @@ public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> s
194197
/// </summary>
195198
/// <typeparam name="TSource">The type of the source list.</typeparam>
196199
/// <typeparam name="TResult">The type of the mapped items.</typeparam>
200+
[DebuggerDisplay("Count = {CountForDebugger}")]
197201
private sealed partial class SelectListIterator<TSource, TResult> : Iterator<TResult>
198202
{
199203
private readonly List<TSource> _source;
@@ -208,6 +212,8 @@ public SelectListIterator(List<TSource> source, Func<TSource, TResult> selector)
208212
_selector = selector;
209213
}
210214

215+
private int CountForDebugger => _source.Count;
216+
211217
public override Iterator<TResult> Clone() => new SelectListIterator<TSource, TResult>(_source, _selector);
212218

213219
public override bool MoveNext()
@@ -241,6 +247,7 @@ public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> s
241247
/// </summary>
242248
/// <typeparam name="TSource">The type of the source list.</typeparam>
243249
/// <typeparam name="TResult">The type of the mapped items.</typeparam>
250+
[DebuggerDisplay("Count = {CountForDebugger}")]
244251
private sealed partial class SelectIListIterator<TSource, TResult> : Iterator<TResult>
245252
{
246253
private readonly IList<TSource> _source;
@@ -255,6 +262,8 @@ public SelectIListIterator(IList<TSource> source, Func<TSource, TResult> selecto
255262
_selector = selector;
256263
}
257264

265+
private int CountForDebugger => _source.Count;
266+
258267
public override Iterator<TResult> Clone() => new SelectIListIterator<TSource, TResult>(_source, _selector);
259268

260269
public override bool MoveNext()

0 commit comments

Comments
 (0)