Skip to content

Commit

Permalink
Improve StringValues, StringSegment and IChangeToken debugging (#88960)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Jul 16, 2023
1 parent 061e677 commit 6c29448
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Threading;
using Microsoft.Extensions.Internal;

Expand All @@ -10,6 +11,7 @@ namespace Microsoft.Extensions.Primitives
/// <summary>
/// A <see cref="IChangeToken"/> implementation using <see cref="CancellationToken"/>.
/// </summary>
[DebuggerDisplay("HasChanged = {HasChanged}")]
public class CancellationChangeToken : IChangeToken
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.Extensions.Primitives
/// <summary>
/// An <see cref="IChangeToken"/> which represents one or more <see cref="IChangeToken"/> instances.
/// </summary>
[DebuggerDisplay("HasChanged = {HasChanged}")]
public class CompositeChangeToken : IChangeToken
{
private static readonly Action<object?> _onChangeDelegate = OnChange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.Extensions.Primitives
/// <summary>
/// An optimized representation of a substring.
/// </summary>
[DebuggerDisplay("{Value}")]
public readonly struct StringSegment : IEquatable<StringSegment>, IEquatable<string?>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.Extensions.Primitives
/// <summary>
/// Represents zero/null, one, or many strings in an efficient way.
/// </summary>
[DebuggerDisplay("{ToString()}")]
[DebuggerTypeProxy(typeof(StringValuesDebugView))]
public readonly struct StringValues : IList<string?>, IReadOnlyList<string?>, IEquatable<StringValues>, IEquatable<string?>, IEquatable<string?[]?>
{
/// <summary>
Expand Down Expand Up @@ -825,5 +827,11 @@ public void Dispose()
{
}
}

private sealed class StringValuesDebugView(StringValues values)
{
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public string?[] Items => values.ToArray();
}
}
}

0 comments on commit 6c29448

Please sign in to comment.