Skip to content

Commit 46e6189

Browse files
committed
Add debugger attributes
1 parent 89b5d4c commit 46e6189

8 files changed

Lines changed: 85 additions & 0 deletions

Source/Common/OneOrMany{T}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Diagnostics.CodeAnalysis;
78
using System.Linq;
89
using System.Runtime.CompilerServices;
@@ -12,11 +13,13 @@ namespace Schema.NET;
1213
/// </summary>
1314
/// <typeparam name="T">The type of the values.</typeparam>
1415
/// <seealso cref="IReadOnlyCollection{T}" />
16+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1517
[CollectionBuilder(typeof(OneOrManyBuilder), nameof(OneOrManyBuilder.Create))]
1618
#pragma warning disable CA1710 // Identifiers should have correct suffix.
1719
public readonly struct OneOrMany<T> : IReadOnlyCollection<T>, IValues, IEquatable<OneOrMany<T>>
1820
#pragma warning restore CA1710 // Identifiers should have correct suffix.
1921
{
22+
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
2023
private readonly T[]? collection;
2124

2225
/// <summary>
@@ -286,6 +289,12 @@ public bool Equals(OneOrMany<T> other)
286289
/// </summary>
287290
/// <returns>A <see cref="ReadOnlySpan{T}"/> wrapping the current items.</returns>
288291
public ReadOnlySpan<T> AsSpan() => this.collection.AsSpan();
292+
293+
/// <summary>
294+
/// Gets the string to display in the debugger watches window for this instance.
295+
/// </summary>
296+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
297+
private string DebuggerDisplay => $"Length = {this.Count}";
289298
}
290299

291300
/// <summary>

Source/Common/Values{T1,T2,T3,T4,T5,T6,T7}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Runtime.CompilerServices;
89

@@ -16,6 +17,8 @@ namespace Schema.NET;
1617
/// <typeparam name="T5">The fifth type the values can take.</typeparam>
1718
/// <typeparam name="T6">The sixth type the values can take.</typeparam>
1819
/// <typeparam name="T7">The seventh type the values can take.</typeparam>
20+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
21+
[DebuggerTypeProxy(typeof(IValuesDebugView))]
1922
[CollectionBuilder(typeof(ValuesBuilder), nameof(ValuesBuilder.Create))]
2023
public readonly struct Values<T1, T2, T3, T4, T5, T6, T7> : IReadOnlyCollection<object?>, IValues, IEquatable<Values<T1, T2, T3, T4, T5, T6, T7>>
2124
{
@@ -895,6 +898,12 @@ public bool Equals(Values<T1, T2, T3, T4, T5, T6, T7> other)
895898
/// </returns>
896899
public override int GetHashCode() =>
897900
HashCode.Of(this.Value1).And(this.Value2).And(this.Value3).And(this.Value4).And(this.Value5).And(this.Value6).And(this.Value7);
901+
902+
/// <summary>
903+
/// Gets the string to display in the debugger watches window for this instance.
904+
/// </summary>
905+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
906+
private string DebuggerDisplay => $"Length = {this.Count}";
898907
}
899908

900909
public static partial class ValuesBuilder

Source/Common/Values{T1,T2,T3,T4,T5,T6}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Runtime.CompilerServices;
89

@@ -15,6 +16,8 @@ namespace Schema.NET;
1516
/// <typeparam name="T4">The fourth type the values can take.</typeparam>
1617
/// <typeparam name="T5">The fifth type the values can take.</typeparam>
1718
/// <typeparam name="T6">The sixth type the values can take.</typeparam>
19+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
20+
[DebuggerTypeProxy(typeof(IValuesDebugView))]
1821
[CollectionBuilder(typeof(ValuesBuilder), nameof(ValuesBuilder.Create))]
1922
public readonly struct Values<T1, T2, T3, T4, T5, T6> : IReadOnlyCollection<object?>, IValues, IEquatable<Values<T1, T2, T3, T4, T5, T6>>
2023
{
@@ -775,6 +778,12 @@ public bool Equals(Values<T1, T2, T3, T4, T5, T6> other)
775778
/// </returns>
776779
public override int GetHashCode() =>
777780
HashCode.Of(this.Value1).And(this.Value2).And(this.Value3).And(this.Value4).And(this.Value5).And(this.Value6);
781+
782+
/// <summary>
783+
/// Gets the string to display in the debugger watches window for this instance.
784+
/// </summary>
785+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
786+
private string DebuggerDisplay => $"Length = {this.Count}";
778787
}
779788

780789
public static partial class ValuesBuilder

Source/Common/Values{T1,T2,T3,T4,T5}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Runtime.CompilerServices;
89

@@ -14,6 +15,8 @@ namespace Schema.NET;
1415
/// <typeparam name="T3">The third type the values can take.</typeparam>
1516
/// <typeparam name="T4">The fourth type the values can take.</typeparam>
1617
/// <typeparam name="T5">The fifth type the values can take.</typeparam>
18+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
19+
[DebuggerTypeProxy(typeof(IValuesDebugView))]
1720
[CollectionBuilder(typeof(ValuesBuilder), nameof(ValuesBuilder.Create))]
1821
public readonly struct Values<T1, T2, T3, T4, T5> : IReadOnlyCollection<object?>, IValues, IEquatable<Values<T1, T2, T3, T4, T5>>
1922
{
@@ -659,6 +662,12 @@ public bool Equals(Values<T1, T2, T3, T4, T5> other)
659662
/// </returns>
660663
public override int GetHashCode() =>
661664
HashCode.Of(this.Value1).And(this.Value2).And(this.Value3).And(this.Value4).And(this.Value5);
665+
666+
/// <summary>
667+
/// Gets the string to display in the debugger watches window for this instance.
668+
/// </summary>
669+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
670+
private string DebuggerDisplay => $"Length = {this.Count}";
662671
}
663672

664673
public static partial class ValuesBuilder

Source/Common/Values{T1,T2,T3,T4}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Runtime.CompilerServices;
89

@@ -13,6 +14,8 @@ namespace Schema.NET;
1314
/// <typeparam name="T2">The second type the values can take.</typeparam>
1415
/// <typeparam name="T3">The third type the values can take.</typeparam>
1516
/// <typeparam name="T4">The fourth type the values can take.</typeparam>
17+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
18+
[DebuggerTypeProxy(typeof(IValuesDebugView))]
1619
[CollectionBuilder(typeof(ValuesBuilder), nameof(ValuesBuilder.Create))]
1720
public readonly struct Values<T1, T2, T3, T4> : IReadOnlyCollection<object?>, IValues, IEquatable<Values<T1, T2, T3, T4>>
1821
{
@@ -547,6 +550,12 @@ public bool Equals(Values<T1, T2, T3, T4> other)
547550
/// </returns>
548551
public override int GetHashCode() =>
549552
HashCode.Of(this.Value1).And(this.Value2).And(this.Value3).And(this.Value4);
553+
554+
/// <summary>
555+
/// Gets the string to display in the debugger watches window for this instance.
556+
/// </summary>
557+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
558+
private string DebuggerDisplay => $"Length = {this.Count}";
550559
}
551560

552561
public static partial class ValuesBuilder

Source/Common/Values{T1,T2,T3}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Runtime.CompilerServices;
89

@@ -12,6 +13,8 @@ namespace Schema.NET;
1213
/// <typeparam name="T1">The first type the values can take.</typeparam>
1314
/// <typeparam name="T2">The second type the values can take.</typeparam>
1415
/// <typeparam name="T3">The third type the values can take.</typeparam>
16+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
17+
[DebuggerTypeProxy(typeof(IValuesDebugView))]
1518
[CollectionBuilder(typeof(ValuesBuilder), nameof(ValuesBuilder.Create))]
1619
public readonly struct Values<T1, T2, T3> : IReadOnlyCollection<object?>, IValues, IEquatable<Values<T1, T2, T3>>
1720
{
@@ -438,6 +441,12 @@ public bool Equals(Values<T1, T2, T3> other)
438441
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
439442
/// </returns>
440443
public override int GetHashCode() => HashCode.Of(this.Value1).And(this.Value2).And(this.Value3);
444+
445+
/// <summary>
446+
/// Gets the string to display in the debugger watches window for this instance.
447+
/// </summary>
448+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
449+
private string DebuggerDisplay => $"Length = {this.Count}";
441450
}
442451

443452
public static partial class ValuesBuilder

Source/Common/Values{T1,T2}.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Schema.NET;
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.Linq;
78
using System.Runtime.CompilerServices;
89

@@ -11,6 +12,8 @@ namespace Schema.NET;
1112
/// </summary>
1213
/// <typeparam name="T1">The first type the values can take.</typeparam>
1314
/// <typeparam name="T2">The second type the values can take.</typeparam>
15+
[DebuggerDisplay("{DebuggerDisplay,nq}")]
16+
[DebuggerTypeProxy(typeof(IValuesDebugView))]
1417
[CollectionBuilder(typeof(ValuesBuilder), nameof(ValuesBuilder.Create))]
1518
public readonly struct Values<T1, T2> : IReadOnlyCollection<object?>, IValues, IEquatable<Values<T1, T2>>
1619
{
@@ -334,6 +337,12 @@ public bool Equals(Values<T1, T2> other)
334337
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
335338
/// </returns>
336339
public override int GetHashCode() => HashCode.Of(this.Value1).And(this.Value2);
340+
341+
/// <summary>
342+
/// Gets the string to display in the debugger watches window for this instance.
343+
/// </summary>
344+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
345+
private string DebuggerDisplay => $"Length = {this.Count}";
337346
}
338347

339348
/// <summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Schema.NET;
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Linq;
7+
8+
internal sealed class IValuesDebugView
9+
{
10+
private readonly IEnumerable<object> collection;
11+
12+
public IValuesDebugView(IEnumerable<object> collection)
13+
{
14+
ArgumentNullException.ThrowIfNull(collection);
15+
16+
this.collection = collection;
17+
}
18+
19+
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
20+
public object[] Items => this.collection.ToArray();
21+
}
22+

0 commit comments

Comments
 (0)