You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement ToString() on System.Collections.DictionaryEntry #59292
It's so frustrating when you see a useless type name in the logs for example, where it could have been meaningful and helpful to have the actual values.
That's a good point, but unfortunately nobody writes it that way.
Only because the feature is new and nobody's used it yet. But at the very least, any new applications of DebuggerDisplay could (and I believe should) make use of the new feature so that mistakes like the one you linked can be spotted at compile-time.
There's no escaping or anything else fancy here, as anything like that would have performance hits for negligible value (only in odd cases). Here are the tests I have illustrating what the behavior would be:
It does not do any truncation. Scanning through all places where we override ToString, I see lots of instances where we emit or build unbounded strings; I haven't found any where we truncate.
ghost added
in-prThere is an active PR which will close this issue when it is merged
Activity
eiriktsarpalis commentedon Sep 19, 2021
So, should this be a change to how
ToString()is implemented or would it make more sense to add aDebuggerDisplayAttribute?KirillOsenkov commentedon Sep 20, 2021
I'd prefer
ToString()because there are several advantages:ToString()is useful in various other contexts, such as various text logs, format strings, interpolated strings, printf debugging, etc.KeyValuePair<TKey, TValue>usesToString()DebuggerDisplayis stringly typed)ToString()KirillOsenkov commentedon Sep 20, 2021
It's so frustrating when you see a useless type name in the logs for example, where it could have been meaningful and helpful to have the actual values.
Joe4evr commentedon Sep 20, 2021
Current preview can have compiler verification, tho:
KirillOsenkov commentedon Sep 20, 2021
That's a good point, but unfortunately nobody writes it that way. Look at all existing DebuggerDisplay usages:
https://source.dot.net/#System.Private.CoreLib/DebuggerDisplayAttribute.cs,761078d4519dc54e,references
I just had to fix this recently because someone refactored code and forgot to update DebuggerDisplay:
https://github.com/dotnet/msbuild/pull/6650/files
Joe4evr commentedon Sep 20, 2021
Only because the feature is new and nobody's used it yet. But at the very least, any new applications of
DebuggerDisplaycould (and I believe should) make use of the new feature so that mistakes like the one you linked can be spotted at compile-time.krwq commentedon Sep 27, 2021
@KirillOsenkov would you expect to add any string escaping into
ToString? I'd expect to make it consistent with perhaps Tuple or other similar classesKirillOsenkov commentedon Sep 27, 2021
sure, anything is fine, ValueTuple, KVP, as long as it’s something.
KirillOsenkov commentedon Sep 27, 2021
curious how ToString looks for anonymous types and old Tuples
eiriktsarpalis commentedon Sep 27, 2021
FWIW both prettyprint their contents.
jeffhandley commentedon Feb 6, 2022
I'm tempted to just reuse the implementation for
KeyValuePair.ToString(). It's available as a static internal:There's no escaping or anything else fancy here, as anything like that would have performance hits for negligible value (only in odd cases). Here are the tests I have illustrating what the behavior would be:
Any objections to taking this approach? Preview: https://github.com/dotnet/runtime/compare/main...jeffhandley:jeffhandley/59292-de-tostring?expand=1
danmoseley commentedon Feb 6, 2022
Does it truncate if key or value is huge? And do we want it to?
jeffhandley commentedon Feb 6, 2022
It does not do any truncation. Scanning through all places where we override
ToString, I see lots of instances where we emit or build unbounded strings; I haven't found any where we truncate.