Google.Protobuf.JsonFormatter.ToDiagnosticString C# (CSharp) Method

ToDiagnosticString() public static method

Converts a message to JSON for diagnostic purposes with no extra context.

This differs from calling Format(IMessage) on the default JSON formatter in its handling of Any. As no type registry is available in object.ToString calls, the normal way of resolving the type of an Any message cannot be applied. Instead, a JSON property named @value is included with the base64 data from the Any.Value property of the message.

The value returned by this method is only designed to be used for diagnostic purposes. It may not be parsable by JsonParser, and may not be parsable by other Protocol Buffer implementations.

public static ToDiagnosticString ( IMessage message ) : string
message IMessage The message to format for diagnostic purposes.
return string
        public static string ToDiagnosticString(IMessage message)
        {
            ProtoPreconditions.CheckNotNull(message, nameof(message));
            return diagnosticFormatter.Format(message);
        }

Usage Example

Example #1
0
 public override string ToString()
 {
     return(JsonFormatter.ToDiagnosticString(this));
 }