Status.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #region Copyright notice and license
  2. // Copyright 2015 gRPC authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. namespace Grpc.Core
  17. {
  18. /// <summary>
  19. /// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
  20. /// </summary>
  21. public struct Status
  22. {
  23. /// <summary>
  24. /// Default result of a successful RPC. StatusCode=OK, empty details message.
  25. /// </summary>
  26. public static readonly Status DefaultSuccess = new Status(StatusCode.OK, "");
  27. /// <summary>
  28. /// Default result of a cancelled RPC. StatusCode=Cancelled, empty details message.
  29. /// </summary>
  30. public static readonly Status DefaultCancelled = new Status(StatusCode.Cancelled, "");
  31. readonly StatusCode statusCode;
  32. readonly string detail;
  33. /// <summary>
  34. /// Creates a new instance of <c>Status</c>.
  35. /// </summary>
  36. /// <param name="statusCode">Status code.</param>
  37. /// <param name="detail">Detail.</param>
  38. public Status(StatusCode statusCode, string detail)
  39. {
  40. this.statusCode = statusCode;
  41. this.detail = detail;
  42. }
  43. /// <summary>
  44. /// Gets the gRPC status code. OK indicates success, all other values indicate an error.
  45. /// </summary>
  46. public StatusCode StatusCode
  47. {
  48. get
  49. {
  50. return statusCode;
  51. }
  52. }
  53. /// <summary>
  54. /// Gets the detail.
  55. /// </summary>
  56. public string Detail
  57. {
  58. get
  59. {
  60. return detail;
  61. }
  62. }
  63. /// <summary>
  64. /// Returns a <see cref="System.String"/> that represents the current <see cref="Grpc.Core.Status"/>.
  65. /// </summary>
  66. public override string ToString()
  67. {
  68. return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
  69. }
  70. }
  71. }