andrewlock / StronglyTypedId

A Rosyln-powered generator for strongly-typed IDs
MIT License
1.53k stars 82 forks source link

[Proposal] Add DebuggerDisplay to generated code #98

Closed espenrl closed 10 months ago

espenrl commented 1 year ago

For increased productivity while debugging, please consider adding DebuggerDisplay attribute.

I always add DebuggerDisplay to my StronglyTypedId structs, but it would be awesome if the generated code added it.

[DebuggerDisplay("{Value}")]
[StronglyTypedId]
public partial struct UserId { }
andrewlock commented 10 months ago

According to the docs, this shouldn't be necessary if ToString() is overridden:

For example, if a C# object has an overridden ToString(), the debugger will call the override and show its result instead of the standard {}. Thus, if you have overridden ToString(), you do not need to use DebuggerDisplayAttribute. If you use both, the DebuggerDisplayAttribute attribute takes precedence over the ToString() override

Given we always override ToString(), I don't think we need this? My tests seem to show that it works as-is too:

image

I'll close this as I don't think it's required, but feel free to re-open it if I'm wrong about something here, thanks!