ICustomDiagnosticMessage.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #region Copyright notice and license
  2. // Protocol Buffers - Google's data interchange format
  3. // Copyright 2016 Google Inc. All rights reserved.
  4. // https://developers.google.com/protocol-buffers/
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are
  8. // met:
  9. //
  10. // * Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. // * Redistributions in binary form must reproduce the above
  13. // copyright notice, this list of conditions and the following disclaimer
  14. // in the documentation and/or other materials provided with the
  15. // distribution.
  16. // * Neither the name of Google Inc. nor the names of its
  17. // contributors may be used to endorse or promote products derived from
  18. // this software without specific prior written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. #endregion
  32. namespace Google.Protobuf
  33. {
  34. /// <summary>
  35. /// A message type that has a custom string format for diagnostic purposes.
  36. /// </summary>
  37. /// <remarks>
  38. /// <para>
  39. /// Calling <see cref="object.ToString"/> on a generated message type normally
  40. /// returns the JSON representation. If a message type implements this interface,
  41. /// then the <see cref="ToDiagnosticString"/> method will be called instead of the regular
  42. /// JSON formatting code, but only when <c>ToString()</c> is called either on the message itself
  43. /// or on another message which contains it. This does not affect the normal JSON formatting of
  44. /// the message.
  45. /// </para>
  46. /// <para>
  47. /// For example, if you create a proto message representing a GUID, the internal
  48. /// representation may be a <c>bytes</c> field or four <c>fixed32</c> fields. However, when debugging
  49. /// it may be more convenient to see a result in the same format as <see cref="System.Guid"/> provides.
  50. /// </para>
  51. /// <para>This interface extends <see cref="IMessage"/> to avoid it accidentally being implemented
  52. /// on types other than messages, where it would not be used by anything in the framework.</para>
  53. /// </remarks>
  54. public interface ICustomDiagnosticMessage : IMessage
  55. {
  56. /// <summary>
  57. /// Returns a string representation of this object, for diagnostic purposes.
  58. /// </summary>
  59. /// <remarks>
  60. /// This method is called when a message is formatted as part of a <see cref="object.ToString"/>
  61. /// call. It does not affect the JSON representation used by <see cref="JsonFormatter"/> other than
  62. /// in calls to <see cref="JsonFormatter.ToDiagnosticString(IMessage)"/>. While it is recommended
  63. /// that the result is valid JSON, this is never assumed by the Protobuf library.
  64. /// </remarks>
  65. /// <returns>A string representation of this object, for diagnostic purposes.</returns>
  66. string ToDiagnosticString();
  67. }
  68. }