Add some DebuggerDisplay attributes in System.Linq (dotnet/corefx#41386)
authorStephen Toub <stoub@microsoft.com>
Fri, 27 Sep 2019 18:19:52 +0000 (14:19 -0400)
committerSantiago Fernandez Madero <safern@microsoft.com>
Fri, 27 Sep 2019 18:19:52 +0000 (11:19 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/e667c29636a622eb4f9493f75232b44e0ae90b29

src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Range.cs
src/libraries/System.Linq/src/System/Linq/Repeat.cs
src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Select.cs

index 1b8d9ff..4c59749 100644 (file)
@@ -17,6 +17,7 @@ namespace System.Linq
     /// Returning an instance of this type is useful to quickly handle scenarios where it is known
     /// that an operation will result in zero elements.
     /// </remarks>
+    [DebuggerDisplay("Count = 0")]
     internal sealed class EmptyPartition<TElement> : IPartition<TElement>, IEnumerator<TElement>
     {
         /// <summary>
@@ -150,6 +151,7 @@ namespace System.Linq
         /// An iterator that yields the items of part of an <see cref="IList{TSource}"/>.
         /// </summary>
         /// <typeparam name="TSource">The type of the source list.</typeparam>
+        [DebuggerDisplay("Count = {Count}")]
         private sealed class ListPartition<TSource> : Iterator<TSource>, IPartition<TSource>
         {
             private readonly IList<TSource> _source;
index a26ed82..10d3d61 100644 (file)
@@ -28,6 +28,7 @@ namespace System.Linq
         /// <summary>
         /// An iterator that yields a range of consecutive integers.
         /// </summary>
+        [DebuggerDisplay("Count = {CountForDebugger}")]
         private sealed partial class RangeIterator : Iterator<int>
         {
             private readonly int _start;
@@ -40,6 +41,8 @@ namespace System.Linq
                 _end = unchecked(start + count);
             }
 
+            private int CountForDebugger => _end - _start;
+
             public override Iterator<int> Clone() => new RangeIterator(_start, _end - _start);
 
             public override bool MoveNext()
index df4812b..a37dc08 100644 (file)
@@ -28,6 +28,7 @@ namespace System.Linq
         /// An iterator that yields the same item multiple times.
         /// </summary>
         /// <typeparam name="TResult">The type of the item.</typeparam>
+        [DebuggerDisplay("Count = {_count}")]
         private sealed partial class RepeatIterator<TResult> : Iterator<TResult>
         {
             private readonly int _count;
index 7ac46f1..bfbff0f 100644 (file)
@@ -683,6 +683,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="TSource">The type of the source list.</typeparam>
         /// <typeparam name="TResult">The type of the mapped items.</typeparam>
+        [DebuggerDisplay("Count = {Count}")]
         private sealed class SelectListPartitionIterator<TSource, TResult> : Iterator<TResult>, IPartition<TResult>
         {
             private readonly IList<TSource> _source;
index 4278e6d..000777a 100644 (file)
@@ -156,6 +156,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="TSource">The type of the source array.</typeparam>
         /// <typeparam name="TResult">The type of the mapped items.</typeparam>
+        [DebuggerDisplay("Count = {CountForDebugger}")]
         private sealed partial class SelectArrayIterator<TSource, TResult> : Iterator<TResult>
         {
             private readonly TSource[] _source;
@@ -170,6 +171,8 @@ namespace System.Linq
                 _selector = selector;
             }
 
+            private int CountForDebugger => _source.Length;
+
             public override Iterator<TResult> Clone() => new SelectArrayIterator<TSource, TResult>(_source, _selector);
 
             public override bool MoveNext()
@@ -194,6 +197,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="TSource">The type of the source list.</typeparam>
         /// <typeparam name="TResult">The type of the mapped items.</typeparam>
+        [DebuggerDisplay("Count = {CountForDebugger}")]
         private sealed partial class SelectListIterator<TSource, TResult> : Iterator<TResult>
         {
             private readonly List<TSource> _source;
@@ -208,6 +212,8 @@ namespace System.Linq
                 _selector = selector;
             }
 
+            private int CountForDebugger => _source.Count;
+
             public override Iterator<TResult> Clone() => new SelectListIterator<TSource, TResult>(_source, _selector);
 
             public override bool MoveNext()
@@ -241,6 +247,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="TSource">The type of the source list.</typeparam>
         /// <typeparam name="TResult">The type of the mapped items.</typeparam>
+        [DebuggerDisplay("Count = {CountForDebugger}")]
         private sealed partial class SelectIListIterator<TSource, TResult> : Iterator<TResult>
         {
             private readonly IList<TSource> _source;
@@ -255,6 +262,8 @@ namespace System.Linq
                 _selector = selector;
             }
 
+            private int CountForDebugger => _source.Count;
+
             public override Iterator<TResult> Clone() => new SelectIListIterator<TSource, TResult>(_source, _selector);
 
             public override bool MoveNext()