-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Improve endpoint metadata debugging #47163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve endpoint metadata debugging #47163
Conversation
Thanks for your PR, @SeanFarrow. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This is not ready yet, as there is a build error due to the fact that the CodeFix that adds methods to the public API has added the ToString method of the EndpointMetadataCollection class to the wrong place. I still need to finish implement ToString for both the Endpoint base class and RouteEndpoint class. |
Thanks @SeanFarrow! I've marked this as a draft since it's not ready yet. Feel free to mark it ready when appropriate. @JamesNK Assigning this one to you for review. |
var metadataTokensBuilder = new StringBuilder(); | ||
foreach(var DataToken in DataTokens) | ||
{ | ||
metadataTokensBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0} ={1}", DataToken.Key, DataToken.Value); | ||
metadataTokensBuilder.AppendLine(); | ||
} | ||
return metadataTokensBuilder.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer comma delimited rather than separate lines. Separate lines can mess up tooling.
Also, include text to label what the data is.
Something like:
var dataTokensDisplay = string.Join(",", DataTokens.Select(t => $"{t.Key}={t.Value}"));
return $"DataTokens: {dataTokensDisplay}";
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return EndpointName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return EndpointName; | |
return $"EndpointName: {EndpointName}"; |
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return SuppressLinkGeneration.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return SuppressLinkGeneration.ToString(); | |
return $"SuppressLinkGeneration = {SuppressLinkGeneration}"; |
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return SuppressMatching.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return SuppressMatching.ToString(); | |
return $"SuppressMatching = {SuppressMatching}"; |
@@ -156,6 +157,24 @@ public EndpointMetadataCollection(params object[] items) | |||
/// <returns>An <see cref="IEnumerator"/> of all metadata items.</returns> | |||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | |||
|
|||
/// <inheritdoc/> | |||
public override string ToString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should override this collection ToString. If someone wants to view the contents then they can do it with a debugger.
Instead, put a debugger display on the collection:
[DebuggerDisplay("Count = {Count}")]
If you want, you could also add a debugger proxy. List<T>
does this for example: https://github.com/dotnet/runtime/blob/73818601becad0d1c6cfc58b5d947db010da2d6b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs#L17-L18. A debugger proxy changes what properties are visible in IDEs when debugging.
You'll need to copy and paste this internal type: https://github.com/dotnet/runtime/blob/73818601becad0d1c6cfc58b5d947db010da2d6b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ICollectionDebugView.cs
Put it under src/Http/Http.Abstractions/src/Internal
and update the namespace to match other files in that directory.
Looking good so far. I think these changes will make debugging endpoint metadata much easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok if we want to do this change, but I would avoid overriding ToString
and instead use [DebuggerDisplay]
and a private method on the types.
This was discussed in API review, and we went with
|
@SeanFarrow What are your plans for this PR? If you don't have time right now to complete it then I can take it over. |
@JamesNK I'm going to pick this up again next week--I am in the process of changing jobs, so have 2 weeks off before the next one starts! Hopefully this is ample time to get this finished. |
…than specifically implementing aDebuggerToString method.
…emove the DebuggerToString method.
… in the RouteNameMetadata class.
…the use of StringBuilder.
…the use of StringBuilder.
@JamesNK Are you able to pick this up please. I thought I'd have more time than I have, but this won't be the case--at least not before 8.0, given my mum is not well and I'm changing jobs! Thanks, |
Sure, I can finish this off. Thanks for starting. |
Replaced by #48207 |
{PR title}
This PR improves endpoint metadata debugging.
Description
This PR overrides ToString where necessary to improve endpoint metadata debugging.
Fixes #39792