-
Notifications
You must be signed in to change notification settings - Fork 10.4k
define RouteValuesAddress .ToString () #39753
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
Conversation
/// <summary> | ||
/// Formats the address as string "Name(ExplicitValues)" for tracing/debugging. | ||
/// </summary> | ||
public override string ToString () => $"{RouteName}(" + string.Join(',', from kv in ExplicitValues select $"{kv.Key}=[{kv.Value}]") + ")"; |
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.
Can you use the method call syntax instead of LINQ? we don't use linq anywhere in the repo
Looks good to me /cc: @JamesNK in case he has thoughts |
Was there a PR some time ago about adding ToString to many types of route metadata? I have some memory of one. Was that merged or not? |
@JamesNK I don't remember TBH |
@JamesNK I think they are different scenarios? In this case is about logging (and I checked it only happens in Debug or Trace) so I think is much more limited in scope. For things like Endpoints I think I also agree that it should be DebuggerDisplay() |
I think we should discuss this in API review. |
Thank you for your API proposal. I'm removing the |
@@ -3,6 +3,7 @@ | |||
|
|||
#nullable enable | |||
|
|||
using System.Collections.Immutable; |
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.
using System.Collections.Immutable; |
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 tried, it will not build.
Why not just fix the log? |
How much do we care about changing the type of objects in the |
Consider all of #35231 along with this change in API review. Making endpoint metadata more debuggable is good. |
@@ -24,4 +25,7 @@ public class RouteValuesAddress | |||
/// Gets or sets ambient route values from the current HTTP request. | |||
/// </summary> | |||
public RouteValueDictionary? AmbientValues { get; set; } | |||
|
|||
/// <inheritdoc /> | |||
public override string? ToString() => $"{RouteName}({string.Join(',', ExplicitValues.Select(kv => $"{kv.Key}=[{kv.Value}]"))})"; |
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.
If we end up doing this, we should cache it.
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.
Why do you think we should cache it?
Head branch was pushed to by a user without write access
readonly Lazy<string> asString; | ||
|
||
/// <summary> | ||
/// The constructor prepares the internal state of the object. | ||
/// </summary> | ||
public RouteValuesAddress() | ||
{ | ||
asString = new Lazy<string>(() => $"{RouteName}({string.Join(',', ExplicitValues.Select(kv => $"{kv.Key}=[{kv.Value}]"))})"); | ||
} |
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.
This doesn't need a public constructor. Caching this on the constructor is wrong since values can change after the first ToString
call has been issued.
We also don't need to use Lazy
as this code is not used in a multi-threaded context.
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.
Do you want to track changes to the values so that we could invalidate the cache? This gets more and more Byzantine 😱
Thanks for the PR @yecril71pl. We still need to decide whether we want to approve the API along with the other ToString() overrides suggested in #39792. We plan to discuss this next Monday. We may end up deciding not to approve the API or decide not to do caching. I recommend leaving the PR as-is until then. That way the whole team can get on the same page in terms of feedback and you don't have to do so many iterations. |
The converter is linear, this is a debug API, caching is for mission-critical features. |
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.
This went through API review today. Merging.
define RouteValuesAddress .ToString ()
Summary of the changes (Less than 80 chars)
Description
Override
RouteValuesAddress .ToString ()
as Name(ExplicitValues) for tracing/debugging.Fixes #39708