From c5e4027e9bf53f372aa2d94482eb43f73487ea9f Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 27 Sep 2023 10:31:30 +0800 Subject: [PATCH] Add debugger display to Status --- src/Grpc.Core.Api/Status.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Grpc.Core.Api/Status.cs b/src/Grpc.Core.Api/Status.cs index 01055cd9e..45d795562 100644 --- a/src/Grpc.Core.Api/Status.cs +++ b/src/Grpc.Core.Api/Status.cs @@ -15,6 +15,7 @@ #endregion using System; +using System.Diagnostics; namespace Grpc.Core; @@ -22,6 +23,7 @@ namespace Grpc.Core; /// /// Represents RPC result, which consists of and an optional detail string. /// +[DebuggerDisplay("{DebuggerToString(),nq}")] public struct Status { /// @@ -93,4 +95,19 @@ public override string ToString() } return $"Status(StatusCode=\"{StatusCode}\", Detail=\"{Detail}\")"; } + + private string DebuggerToString() + { + var text = $"StatusCode = {StatusCode}"; + if (!string.IsNullOrEmpty(Detail)) + { + text += $@", Detail = ""{Detail}"""; + } + if (DebugException != null) + { + text += $@", DebugException = ""{DebugException.GetType()}: {DebugException.Message}"""; + } + + return text; + } }