Skip to content

Commit b069f0c

Browse files
authored
Better debugger display (#48)
* Add debugger attributes
1 parent 89b5d4c commit b069f0c

10 files changed

Lines changed: 92 additions & 1 deletion

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# (Temporary?) Fork of [Schema.NET](https://github.com/RehanSaeed/Schema.NET)
22
### Changes:
33
- Add targets for .NET 8 - 10
4-
- Add support for [collection expressions](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions)
4+
- Removed targets for EOL .NET versions and .Net Framework
5+
- Add support for [collection expressions](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions) [#36](https://github.com/TimmyMC/Schema.NET/pull/36)
6+
- Added debugging attributes [#48](https://github.com/TimmyMC/Schema.NET/pull/48)
57
- Performance improvements
68
### Why the fork?
79
> I created this fork for to use in a large webshop, I initially wanted the package to target .net 8.<br/>

Schema.NET.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{AF228B
107107
Source\Common\Values{T1,T2,T3,T4}.cs = Source\Common\Values{T1,T2,T3,T4}.cs
108108
Source\Common\Values{T1,T2,T3}.cs = Source\Common\Values{T1,T2,T3}.cs
109109
Source\Common\Values{T1,T2}.cs = Source\Common\Values{T1,T2}.cs
110+
Source\Common\IValuesDebugView.cs = Source\Common\IValuesDebugView.cs
110111
EndProjectSection
111112
EndProject
112113
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Schema.NET.Updater", "Tools\Schema.NET.Updater\Schema.NET.Updater.csproj", "{8923F9E2-4BB8-45F9-9A85-863F381B46EE}"

Source/Common/IValuesDebugView.cs

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+

Source/Common/OneOrMany{T}.cs

Lines changed: 12 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>
@@ -107,18 +110,21 @@ public OneOrMany(IEnumerable<object?> collection) : this(collection.Cast<T?>().T
107110
/// <summary>
108111
/// Gets the number of elements contained in the <see cref="OneOrMany{T}"/>.
109112
/// </summary>
113+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
110114
public int Count => this.collection?.Length ?? 0;
111115

112116
/// <summary>
113117
/// Gets a value indicating whether this instance has a single item value.
114118
/// </summary>
115119
/// <value><c>true</c> if this instance has a single item value; otherwise, <c>false</c>.</value>
120+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
116121
public bool HasOne { get; }
117122

118123
/// <summary>
119124
/// Gets a value indicating whether this instance has more than one value.
120125
/// </summary>
121126
/// <value><c>true</c> if this instance has more than one value; otherwise, <c>false</c>.</value>
127+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
122128
public bool HasMany => this.collection?.Length > 1;
123129

124130
/// <summary>
@@ -286,6 +292,12 @@ public bool Equals(OneOrMany<T> other)
286292
/// </summary>
287293
/// <returns>A <see cref="ReadOnlySpan{T}"/> wrapping the current items.</returns>
288294
public ReadOnlySpan<T> AsSpan() => this.collection.AsSpan();
295+
296+
/// <summary>
297+
/// Gets the string to display in the debugger watches window for this instance.
298+
/// </summary>
299+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
300+
private string DebuggerDisplay => $"Length = {this.Count}";
289301
}
290302

291303
/// <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>

0 commit comments

Comments
 (0)