Skip to content

Commit

Permalink
Improve .NET debugging of Protobuf messages (#13838)
Browse files Browse the repository at this point in the history
Generated .NET protobuf messages override `ToString` and return JSON. By default, the .NET debugger displays the result from `ToString` and wraps it in curly braces, e.g. `{{ "Message": "Hello world" }}`. The double curly braces is an ugly result. People expecting JSON here are confused.

This PR adds a [DebuggerDisplayAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerdisplayattribute?view=net-7.0) to generated messages. The attribute tells the debugger to not quote the ToString value with `nq`.

Before:
![image](https://github.com/protocolbuffers/protobuf/assets/303201/b1cc5f45-4064-4ba0-b266-8894ca0f35c8)

After:
![image](https://github.com/protocolbuffers/protobuf/assets/303201/70f6ffc0-9421-428d-bc22-ead7aa82c37f)

I haven't touched the protoc compiler in a long time. I'm guessing I need to build it and then run it to regenerate the checked-in code. I don't suppose someone else could do that? It would save me a lot of time 😬

Closes #13838

COPYBARA_INTEGRATE_REVIEW=#13838 from JamesNK:jamesnk/csharp-message-debuggerdisplay 5222b82
PiperOrigin-RevId: 567659327
  • Loading branch information
JamesNK authored and Copybara-Service committed Sep 22, 2023
1 parent a30d71d commit e519c62
Showing 1 changed file with 220 additions and 216 deletions.

0 comments on commit e519c62

Please sign in to comment.